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 a73bce56e3..eaf89fc589 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.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.NewInstanceCreation; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.PresenceCheck; @@ -97,6 +98,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { private final List constructorConstantMappings; private final List subclassMappings; private final Type returnTypeToConstruct; + private final NewInstanceCreation newInstance; private final BuilderType returnTypeBuilder; private final MethodReference finalizerMethod; private final String finalizedResultName; @@ -2184,6 +2186,9 @@ else if ( sourceParameterNames.contains( mapping.getSourceBeanName() ) ) { } } this.returnTypeToConstruct = returnTypeToConstruct; + this.newInstance = ( returnTypeToConstruct != null && getFactoryMethod() == null ) + ? NewInstanceCreation.forType( returnTypeToConstruct ) + : null; this.subclassMappings = subclassMappings; this.sourceParametersReassignments = sourceParametersReassignments; } @@ -2246,6 +2251,10 @@ public Type getReturnTypeToConstruct() { return returnTypeToConstruct; } + public NewInstanceCreation getNewInstance() { + return newInstance; + } + public boolean hasSubclassMappings() { return !subclassMappings.isEmpty(); } @@ -2279,7 +2288,7 @@ public Set getImportTypes() { } if ( returnTypeToConstruct != null ) { - types.addAll( returnTypeToConstruct.getImportTypes() ); + types.addAll( newInstance != null ? newInstance.getImportTypes() : returnTypeToConstruct.getImportTypes() ); } if ( returnTypeBuilder != null ) { types.add( returnTypeBuilder.getOwningType() ); 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 90b50baf25..cf7bc6e2eb 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 @@ -9,6 +9,7 @@ import java.util.Set; import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.NewInstanceCreation; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; @@ -27,6 +28,7 @@ public class IterableCreation extends ModelElement { private final Type resultType; private final Parameter sourceParameter; private final MethodReference factoryMethod; + private final NewInstanceCreation newInstance; private final boolean canUseSize; private final boolean loadFactorAdjustment; @@ -34,6 +36,7 @@ private IterableCreation(Type resultType, Parameter sourceParameter, MethodRefer this.resultType = resultType; this.sourceParameter = sourceParameter; this.factoryMethod = factoryMethod; + this.newInstance = factoryMethod == null ? NewInstanceCreation.forType( resultType ) : null; this.canUseSize = ( sourceParameter.getType().isCollectionOrMapType() || sourceParameter.getType().isArrayType() ) && resultType.getImplementation() != null && resultType.getImplementation().hasInitialCapacityConstructor(); @@ -57,6 +60,10 @@ public MethodReference getFactoryMethod() { return this.factoryMethod; } + public NewInstanceCreation getNewInstance() { + return newInstance; + } + public boolean isCanUseSize() { return canUseSize; } @@ -68,8 +75,8 @@ public boolean isLoadFactorAdjustment() { @Override public Set getImportTypes() { Set types = new HashSet<>(); - if ( factoryMethod == null && resultType.getImplementationType() != null ) { - types.addAll( resultType.getImplementationType().getImportTypes() ); + if ( newInstance != null ) { + types.addAll( newInstance.getImportTypes() ); } if ( isEnumSet() ) { 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 875368b014..ce347321c9 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 @@ -61,7 +61,7 @@ public ExistingInstanceSetterWrapperForCollectionsAndMaps(Assignment decoratedAs public Set getImportTypes() { Set imported = new HashSet<>( super.getImportTypes() ); if ( isMapNullToDefault() && ( targetType.getImplementationType() != null ) ) { - imported.add( targetType.getImplementationType() ); + imported.addAll( getNewInstance().getImportTypes() ); } return imported; } 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 14eb39cf04..8ef71f7c0d 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 @@ -11,6 +11,7 @@ import java.util.Set; import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.NewInstanceCreation; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; @@ -26,6 +27,7 @@ public class SetterWrapperForCollectionsAndMapsWithNullCheck extends WrapperForC private final Type targetType; private final TypeFactory typeFactory; + private final NewInstanceCreation newInstance; public SetterWrapperForCollectionsAndMapsWithNullCheck(Assignment decoratedAssignment, List thrownTypesToExclude, @@ -40,19 +42,14 @@ public SetterWrapperForCollectionsAndMapsWithNullCheck(Assignment decoratedAssig ); this.targetType = targetType; this.typeFactory = typeFactory; + this.newInstance = NewInstanceCreation.forType( targetType ); } @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() ); - } - + imported.addAll( newInstance.getImportTypes() ); if ( isEnumSet() ) { imported.add( typeFactory.getType( EnumSet.class ) ); } @@ -63,6 +60,10 @@ public Set getImportTypes() { return imported; } + public NewInstanceCreation getNewInstance() { + return newInstance; + } + public boolean isDirectAssignment() { return getType() == DIRECT; } 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 c3d3f9c446..c80b5293c8 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 @@ -11,6 +11,7 @@ import java.util.Set; import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.NewInstanceCreation; import org.mapstruct.ap.internal.model.common.Type; /** @@ -22,7 +23,7 @@ public class UpdateWrapper extends AssignmentWrapper { private final List thrownTypesToExclude; private final Assignment factoryMethod; - private final Type targetImplementationType; + private final NewInstanceCreation newInstance; private final boolean includeSourceNullCheck; private final boolean setExplicitlyToNull; private final boolean setExplicitlyToDefault; @@ -40,27 +41,13 @@ public UpdateWrapper( Assignment decoratedAssignment, super( decoratedAssignment, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; this.factoryMethod = factoryMethod; - this.targetImplementationType = determineImplType( factoryMethod, targetType ); + this.newInstance = ( factoryMethod == null ) ? NewInstanceCreation.forType( targetType ) : null; this.includeSourceNullCheck = includeSourceNullCheck; this.setExplicitlyToDefault = setExplicitlyToDefault; this.setExplicitlyToNull = setExplicitlyToNull; this.mustCastForNull = mustCastForNull; } - 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(); - } - - // no factory method means we create a new instance ourselves and thus need to import the type - return targetType; - } - @Override public List getThrownTypes() { List parentThrownTypes = super.getThrownTypes(); @@ -81,9 +68,8 @@ public Set getImportTypes() { if ( factoryMethod != null ) { imported.addAll( factoryMethod.getImportTypes() ); } - if ( targetImplementationType != null ) { - imported.add( targetImplementationType ); - imported.addAll( targetImplementationType.getTypeParameters() ); + if ( newInstance != null ) { + imported.addAll( newInstance.getImportTypes() ); } return imported; } @@ -92,6 +78,10 @@ public Assignment getFactoryMethod() { return factoryMethod; } + public NewInstanceCreation getNewInstance() { + return newInstance; + } + public boolean isIncludeSourceNullCheck() { return includeSourceNullCheck; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/NewInstanceCreation.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/NewInstanceCreation.java new file mode 100644 index 0000000000..a91d7242cb --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/NewInstanceCreation.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.internal.model.common; + +import java.util.Set; + +/** + * Model element representing the head of a {@code new T<>(...)} expression. It always renders the diamond + * operator for generic types, leaving any type-argument inference to the surrounding Java context. + *

+ * The caller is responsible for emitting the parenthesised argument list after the model. + *

+ * Imports contributed by this element only include the raw constructor type, not its type parameters: the + * generated source never references the parameter classes through this expression, so they are not needed + * here. If the surrounding code references a type parameter elsewhere (e.g. in a variable declaration or a + * method signature), that reference contributes its own imports through its own model element. + * + * @author Filip Hrisafov + */ +public class NewInstanceCreation extends ModelElement { + + private final Type type; + private final Type rawType; + + private NewInstanceCreation(Type type) { + this.type = type; + this.rawType = type.asRawType(); + } + + /** + * Creates a {@link NewInstanceCreation} for the given target type. If the target has an implementation + * type (e.g. {@code Collection} -> {@code ArrayList}), the implementation type is used. + * + * @param targetType the target type to be instantiated; must not be {@code null} + * @return a new model + */ + public static NewInstanceCreation forType(Type targetType) { + Type effective = targetType.getImplementationType() != null + ? targetType.getImplementationType() + : targetType; + return new NewInstanceCreation( effective ); + } + + public Type getType() { + return type; + } + + public Type getRawType() { + return rawType; + } + + public boolean isGeneric() { + return !type.getTypeParameters().isEmpty(); + } + + @Override + public Set getImportTypes() { + return rawType.getImportTypes(); + } +} 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 4ad6ae20db..fd101f0d95 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 @@ -106,7 +106,7 @@ <@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/>(); + <@includeModel object=returnTypeToConstruct/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod targetType=returnTypeToConstruct/><#else><@includeModel object=newInstance/>(); 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 d083bd113d..aff9641d60 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 @@ -15,10 +15,10 @@ <#if resultType.implementation.factoryMethodName?? && ext.useSizeIfPossible?? && ext.useSizeIfPossible && canUseSize> <@includeModel object=resultType.implementationType raw=true />.${resultType.implementation.factoryMethodName}( <@sizeForCreation /> ) <#else> - new <@includeModel object=resultType.implementationType/><#if ext.useSizeIfPossible?? && ext.useSizeIfPossible && canUseSize>( <@sizeForCreation /> )<#else>() + <@includeModel object=newInstance/><#if ext.useSizeIfPossible?? && ext.useSizeIfPossible && canUseSize>( <@sizeForCreation /> )<#else>() <#else> - new <@includeModel object=resultType/>() + <@includeModel object=newInstance/>() <#macro sizeForCreation> 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 8e771f0ddb..02852eec88 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 @@ -46,6 +46,6 @@ <#if enumSet> EnumSet.copyOf( ${nullCheckLocalVarName} ) <#else> - new <#if ext.targetType.implementationType??><@includeModel object=ext.targetType.implementationType/><#else><@includeModel object=ext.targetType/>( ${nullCheckLocalVarName} ) + <@includeModel object=newInstance/>( ${nullCheckLocalVarName} ) \ No newline at end of file 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 index 4582e68a1e..7b9d746767 100644 --- 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 @@ -16,7 +16,7 @@ --> <#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/>(); + <#if ext.targetType.implementationType??><@includeModel object=ext.targetType.implementationType/><#else><@includeModel object=ext.targetType/> ${instanceVar} = <@includeModel object=newInstance/>(); ${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/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl index 3d6172b49d..7fad115bc4 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 @@ -26,6 +26,6 @@ <#if enumSet> EnumSet.copyOf( ${nullCheckLocalVarName} ) <#else> - new <#if ext.targetType.implementationType??><@includeModel object=ext.targetType.implementationType/><#else><@includeModel object=ext.targetType/>( ${nullCheckLocalVarName} ) + <@includeModel object=newInstance/>( ${nullCheckLocalVarName} ) \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/NewInstanceCreation.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/NewInstanceCreation.ftl new file mode 100644 index 0000000000..9b78977245 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/NewInstanceCreation.ftl @@ -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 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.NewInstanceCreation" --> +<@compress single_line=true> +new <@includeModel object=rawType/><#if generic><> + 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 e857a807af..e0f3538c73 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 @@ -170,11 +170,13 @@ Performs a default assignment with a default value. macro: constructTargetObject purpose: Either call the constructor of the target object directly or of the implementing type. + Emits the diamond operator for generic types so type-arguments are inferred from the + assignment context. --> <#-- @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/>() + new <@includeModel object=targetType.implementationType raw=true/><#if targetType.implementationType.typeParameters?size != 0><>() <#elseif targetType.arrayType> new <@includeModel object=targetType.componentType/>[0] <#elseif targetType.sensibleDefault??> @@ -182,7 +184,7 @@ Performs a default assignment with a default value. <#elseif targetType.optionalType> <@includeModel object=targetType.asRawType()/>.of( <@constructTargetObject targetType=targetType.optionalBaseType/> ) <#else> - new <@includeModel object=targetType/>() + new <@includeModel object=targetType raw=true/><#if targetType.typeParameters?size != 0><>() <#-- diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/wildcard/BoundCopyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/generics/wildcard/BoundCopyMapper.java new file mode 100644 index 0000000000..e3324ac737 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/wildcard/BoundCopyMapper.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.generics.wildcard; + +import org.mapstruct.Mapper; + +@Mapper +public interface BoundCopyMapper { + + CollectionSuperTypes copySuperCollection(CollectionSuperTypes collectionSuperTypes); + + CollectionExtendTypes copyExtendsCollection(CollectionExtendTypes collectionExtendTypes); + + MapSuperType copySuperMap(MapSuperType mapSuperType); + + MapExtendType copyExtendMap(MapExtendType mapExtendType); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/wildcard/BoundDirectCopyTest.java b/processor/src/test/java/org/mapstruct/ap/test/generics/wildcard/BoundDirectCopyTest.java new file mode 100644 index 0000000000..d43d319fc3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/wildcard/BoundDirectCopyTest.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.generics.wildcard; + +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; + +/** + * @author hduelme + * + */ +public class BoundDirectCopyTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + BoundCopyMapper.class + ); + + @ProcessorTest + @WithClasses({ + SimpleObject.class, + CollectionSuperTypes.class, + CollectionExtendTypes.class, + MapSuperType.class, + MapExtendType.class, + BoundCopyMapper.class + }) + public void shouldCopyBoundedDirectly() { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/wildcard/MapExtendType.java b/processor/src/test/java/org/mapstruct/ap/test/generics/wildcard/MapExtendType.java new file mode 100644 index 0000000000..9bb43b43ac --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/wildcard/MapExtendType.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.generics.wildcard; + +import java.util.Map; + +public class MapExtendType { + + private Map simpleMap; + + public Map getSimpleMap() { + return simpleMap; + } + + public void setSimpleMap( + Map simpleMap) { + this.simpleMap = simpleMap; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/wildcard/MapSuperType.java b/processor/src/test/java/org/mapstruct/ap/test/generics/wildcard/MapSuperType.java new file mode 100644 index 0000000000..4172efa3de --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/wildcard/MapSuperType.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.generics.wildcard; + +import java.util.Map; + +public class MapSuperType { + + private Map simpleMap; + + public Map getSimpleMap() { + return simpleMap; + } + + public void setSimpleMap( + Map simpleMap) { + this.simpleMap = simpleMap; + } +} 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 index 78c3bea0d7..dd939149fa 100644 --- 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 @@ -40,7 +40,7 @@ public List mapExtend(List auctions) { return null; } - List list = new ArrayList( auctions.size() ); + List list = new ArrayList<>( auctions.size() ); for ( Auction auction : auctions ) { list.add( map( auction ) ); } @@ -54,7 +54,7 @@ public List mapSuper(List auctions) { return null; } - List list = new ArrayList( auctions.size() ); + List list = new ArrayList<>( auctions.size() ); for ( Auction auction : auctions ) { list.add( map( auction ) ); } @@ -113,7 +113,7 @@ protected List paymentListToPaymentDtoList(List list) { return null; } - List list1 = new ArrayList( list.size() ); + List list1 = new ArrayList<>( list.size() ); for ( Payment payment : list ) { list1.add( paymentToPaymentDto( payment ) ); } 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 index d5cfd24723..9d118122bb 100644 --- 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 @@ -30,21 +30,21 @@ public Domain create(DtoWithPresenceCheck source) { if ( source.hasStrings() ) { List list = source.getStrings(); - domain.setStrings( new LinkedHashSet( list ) ); + 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 ) ); + 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 ) ); + domain.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { domain.setStringsWithDefault( helper.toList( "3" ) ); @@ -68,7 +68,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStrings() ) { List list = source.getStrings(); - target.setStrings( new LinkedHashSet( 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 LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -117,7 +117,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStringsWithDefault() ) { List list2 = source.getStringsWithDefault(); - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -140,7 +140,7 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStrings() ) { List list = source.getStrings(); - target.setStrings( new LinkedHashSet( 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 LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -189,7 +189,7 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStringsWithDefault() ) { List list2 = source.getStringsWithDefault(); - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); 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 f36e2e437d..99a731b04c 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 @@ -28,17 +28,17 @@ public Domain create(Dto source) { if ( source != null ) { List list = source.getStrings(); if ( list != null ) { - domain.setStrings( new LinkedHashSet( list ) ); + domain.setStrings( new LinkedHashSet<>( list ) ); } domain.setLongs( stringListToLongSet( source.getStrings() ) ); List list1 = source.getStringsInitialized(); if ( list1 != null ) { - domain.setStringsInitialized( new LinkedHashSet( list1 ) ); + domain.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - domain.setStringsWithDefault( new ArrayList( list2 ) ); + domain.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { domain.setStringsWithDefault( helper.toList( "3" ) ); @@ -59,16 +59,16 @@ public void update(Dto source, Domain target) { target.getStrings().addAll( list ); } else { - target.setStrings( new LinkedHashSet() ); + target.setStrings( new LinkedHashSet<>() ); } } else { List list = source.getStrings(); if ( list != null ) { - target.setStrings( new LinkedHashSet( list ) ); + target.setStrings( new LinkedHashSet<>( list ) ); } else { - target.setStrings( new LinkedHashSet() ); + target.setStrings( new LinkedHashSet<>() ); } } if ( target.getLongs() != null ) { @@ -78,7 +78,7 @@ public void update(Dto source, Domain target) { target.getLongs().addAll( set ); } else { - target.setLongs( new LinkedHashSet() ); + target.setLongs( new LinkedHashSet<>() ); } } else { @@ -87,7 +87,7 @@ public void update(Dto source, Domain target) { target.setLongs( set ); } else { - target.setLongs( new LinkedHashSet() ); + target.setLongs( new LinkedHashSet<>() ); } } if ( target.getStringsInitialized() != null ) { @@ -97,16 +97,16 @@ public void update(Dto source, Domain target) { target.getStringsInitialized().addAll( list1 ); } else { - target.setStringsInitialized( new LinkedHashSet() ); + target.setStringsInitialized( new LinkedHashSet<>() ); } } else { List list1 = source.getStringsInitialized(); if ( list1 != null ) { - target.setStringsInitialized( new LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } else { - target.setStringsInitialized( new LinkedHashSet() ); + target.setStringsInitialized( new LinkedHashSet<>() ); } } if ( target.getLongsInitialized() != null ) { @@ -116,7 +116,7 @@ public void update(Dto source, Domain target) { target.getLongsInitialized().addAll( set1 ); } else { - target.setLongsInitialized( new LinkedHashSet() ); + target.setLongsInitialized( new LinkedHashSet<>() ); } } else { @@ -125,7 +125,7 @@ public void update(Dto source, Domain target) { target.setLongsInitialized( set1 ); } else { - target.setLongsInitialized( new LinkedHashSet() ); + target.setLongsInitialized( new LinkedHashSet<>() ); } } if ( target.getStringsWithDefault() != null ) { @@ -141,7 +141,7 @@ public void update(Dto source, Domain target) { else { List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -161,16 +161,16 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getStrings().addAll( list ); } else { - target.setStrings( new LinkedHashSet() ); + target.setStrings( new LinkedHashSet<>() ); } } else { List list = source.getStrings(); if ( list != null ) { - target.setStrings( new LinkedHashSet( list ) ); + target.setStrings( new LinkedHashSet<>( list ) ); } else { - target.setStrings( new LinkedHashSet() ); + target.setStrings( new LinkedHashSet<>() ); } } if ( target.getLongs() != null ) { @@ -180,7 +180,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getLongs().addAll( set ); } else { - target.setLongs( new LinkedHashSet() ); + target.setLongs( new LinkedHashSet<>() ); } } else { @@ -189,7 +189,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.setLongs( set ); } else { - target.setLongs( new LinkedHashSet() ); + target.setLongs( new LinkedHashSet<>() ); } } if ( target.getStringsInitialized() != null ) { @@ -199,16 +199,16 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getStringsInitialized().addAll( list1 ); } else { - target.setStringsInitialized( new LinkedHashSet() ); + target.setStringsInitialized( new LinkedHashSet<>() ); } } else { List list1 = source.getStringsInitialized(); if ( list1 != null ) { - target.setStringsInitialized( new LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } else { - target.setStringsInitialized( new LinkedHashSet() ); + target.setStringsInitialized( new LinkedHashSet<>() ); } } if ( target.getLongsInitialized() != null ) { @@ -218,7 +218,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getLongsInitialized().addAll( set1 ); } else { - target.setLongsInitialized( new LinkedHashSet() ); + target.setLongsInitialized( new LinkedHashSet<>() ); } } else { @@ -227,7 +227,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.setLongsInitialized( set1 ); } else { - target.setLongsInitialized( new LinkedHashSet() ); + target.setLongsInitialized( new LinkedHashSet<>() ); } } if ( target.getStringsWithDefault() != null ) { @@ -243,7 +243,7 @@ public Domain updateWithReturn(Dto source, Domain target) { else { List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -256,7 +256,7 @@ public Domain updateWithReturn(Dto source, Domain target) { protected Set stringListToLongSet(List list) { if ( list == null ) { - return new LinkedHashSet(); + return new LinkedHashSet<>(); } Set set = LinkedHashSet.newLinkedHashSet( list.size() ); 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 index c61c2c68e8..47e7c5dbfe 100644 --- 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 @@ -30,17 +30,17 @@ public Domain create(Dto source) { List list = source.getStrings(); if ( list != null ) { - domain.setStrings( new LinkedHashSet( list ) ); + domain.setStrings( new LinkedHashSet<>( list ) ); } domain.setLongs( stringListToLongSet( source.getStrings() ) ); List list1 = source.getStringsInitialized(); if ( list1 != null ) { - domain.setStringsInitialized( new LinkedHashSet( list1 ) ); + domain.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - domain.setStringsWithDefault( new ArrayList( list2 ) ); + domain.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { domain.setStringsWithDefault( helper.toList( "3" ) ); @@ -68,7 +68,7 @@ public void update(Dto source, Domain target) { else { List list = source.getStrings(); if ( list != null ) { - target.setStrings( new LinkedHashSet( 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 LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -132,7 +132,7 @@ public void update(Dto source, Domain target) { else { List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -159,7 +159,7 @@ public Domain updateWithReturn(Dto source, Domain target) { else { List list = source.getStrings(); if ( list != null ) { - target.setStrings( new LinkedHashSet( 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 LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -223,7 +223,7 @@ public Domain updateWithReturn(Dto source, Domain target) { else { List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); 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 index 6d01a91ec5..dd90dd2b26 100644 --- 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 @@ -30,21 +30,21 @@ public Domain create(DtoWithPresenceCheck source) { if ( source.hasStrings() ) { List list = source.getStrings(); - domain.setStrings( new LinkedHashSet( list ) ); + 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 ) ); + 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 ) ); + domain.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { domain.setStringsWithDefault( helper.toList( "3" ) ); @@ -68,7 +68,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStrings() ) { List list = source.getStrings(); - target.setStrings( new LinkedHashSet( 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 LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -117,7 +117,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStringsWithDefault() ) { List list2 = source.getStringsWithDefault(); - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -140,7 +140,7 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStrings() ) { List list = source.getStrings(); - target.setStrings( new LinkedHashSet( 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 LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -189,7 +189,7 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStringsWithDefault() ) { List list2 = source.getStringsWithDefault(); - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); 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 index 3f0bee535a..270778c07f 100644 --- 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 @@ -68,7 +68,7 @@ public List sourceFoosToTargetFoos(List foos) { return null; } - List list = new ArrayList( foos.size() ); + List list = new ArrayList<>( foos.size() ); for ( SourceFoo sourceFoo : foos ) { list.add( sourceFooToTargetFoo( sourceFoo ) ); } @@ -96,7 +96,7 @@ public Collection sourceFoosToTargetFoos(Collection foos) return null; } - Collection collection = new ArrayList( foos.size() ); + Collection collection = new ArrayList<>( foos.size() ); for ( SourceFoo sourceFoo : foos ) { collection.add( sourceFooToTargetFoo( sourceFoo ) ); } @@ -110,7 +110,7 @@ public Iterable sourceFoosToTargetFoos(Iterable foos) { return null; } - ArrayList iterable = new ArrayList(); + ArrayList iterable = new ArrayList<>(); for ( SourceFoo sourceFoo : foos ) { iterable.add( sourceFooToTargetFoo( sourceFoo ) ); } @@ -150,7 +150,7 @@ public SortedSet sourceFoosToTargetFooSortedSet(Collection return null; } - SortedSet sortedSet = new TreeSet(); + SortedSet sortedSet = new TreeSet<>(); for ( SourceFoo sourceFoo : foos ) { sortedSet.add( sourceFooToTargetFoo( sourceFoo ) ); } @@ -164,7 +164,7 @@ public NavigableSet sourceFoosToTargetFooNavigableSet(Collection navigableSet = new TreeSet(); + NavigableSet navigableSet = new TreeSet<>(); for ( SourceFoo sourceFoo : foos ) { navigableSet.add( sourceFooToTargetFoo( sourceFoo ) ); } @@ -195,7 +195,7 @@ public SortedMap sourceFooMapToTargetFooSortedMap(Map sortedMap = new TreeMap(); + SortedMap sortedMap = new TreeMap<>(); for ( java.util.Map.Entry entry : foos.entrySet() ) { String key = String.valueOf( entry.getKey() ); @@ -212,7 +212,7 @@ public NavigableMap sourceFooMapToTargetFooNavigableMap(Map navigableMap = new TreeMap(); + NavigableMap navigableMap = new TreeMap<>(); for ( java.util.Map.Entry entry : foos.entrySet() ) { String key = String.valueOf( entry.getKey() ); @@ -229,7 +229,7 @@ public ConcurrentMap sourceFooMapToTargetFooConcurrentMap(Map return null; } - ConcurrentMap concurrentMap = new ConcurrentHashMap( Math.max( (int) ( foos.size() / .75f ) + 1, 16 ) ); + 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() ); @@ -246,7 +246,7 @@ public ConcurrentNavigableMap sourceFooMapToTargetFooConcurre return null; } - ConcurrentNavigableMap concurrentNavigableMap = new ConcurrentSkipListMap(); + ConcurrentNavigableMap concurrentNavigableMap = new ConcurrentSkipListMap<>(); for ( java.util.Map.Entry entry : foos.entrySet() ) { String key = String.valueOf( entry.getKey() ); 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 941bd929a7..605b3a5baa 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 @@ -357,7 +357,7 @@ public List sourceToTarget(List source) { return null; } - List list = new ArrayList( source.size() ); + List list = new ArrayList<>( source.size() ); for ( Float float1 : source ) { list.add( new DecimalFormat( "##.00" ).format( float1 ) ); } @@ -371,7 +371,7 @@ public List targetToSource(List source) { return null; } - List list = new ArrayList( source.size() ); + List list = new ArrayList<>( source.size() ); for ( String string : source ) { try { list.add( new DecimalFormat( "##.00" ).parse( string ).floatValue() ); @@ -390,7 +390,7 @@ public List sourceToTargetWithCustomLocale(List source) { return null; } - List list = new ArrayList( source.size() ); + List list = new ArrayList<>( source.size() ); for ( BigDecimal bigDecimal : source ) { list.add( createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "fr" ) ).format( bigDecimal ) ); } @@ -404,7 +404,7 @@ public List targetToSourceWithCustomLocale(List source) { return null; } - List list = new ArrayList( source.size() ); + List list = new ArrayList<>( source.size() ); for ( String string : source ) { try { list.add( (BigDecimal) createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "fr" ) ).parse( string ) ); 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 c1f4557fbf..6237606b88 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 @@ -81,7 +81,7 @@ public List scientistsToDtosAsList(Scientist[] scientists) { return null; } - List list = new ArrayList( scientists.length ); + 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/_1453/Issue1453MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java index 201b007603..d3395fb320 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 @@ -40,7 +40,7 @@ public List mapExtend(List auctions) { return null; } - List list = new ArrayList( auctions.size() ); + List list = new ArrayList<>( auctions.size() ); for ( Auction auction : auctions ) { list.add( map( auction ) ); } @@ -54,7 +54,7 @@ public List mapSuper(List auctions) { return null; } - List list = new ArrayList( auctions.size() ); + List list = new ArrayList<>( auctions.size() ); for ( Auction auction : auctions ) { list.add( map( auction ) ); } @@ -68,7 +68,7 @@ public Map mapExtend(Map map = new LinkedHashMap( 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 LinkedHashMap( 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() ); @@ -113,7 +113,7 @@ protected List paymentListToPaymentDtoList(List list) { return null; } - List list1 = new ArrayList( list.size() ); + List list1 = new ArrayList<>( list.size() ); for ( Payment payment : list ) { list1.add( paymentToPaymentDto( payment ) ); } @@ -126,7 +126,7 @@ protected Map paymentPaymentMapToPaymentDtoPaymentDtoMap return null; } - Map map1 = new LinkedHashMap( 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/_1685/UserMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java index 3c019a0dd8..b7cb63eb97 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 @@ -157,7 +157,7 @@ protected ContactDataDTO userToContactDataDTO(User user) { contactDataDTO.setAddress( user.getAddress() ); List list = user.getPreferences(); if ( list != null ) { - contactDataDTO.setPreferences( new ArrayList( list ) ); + contactDataDTO.setPreferences( new ArrayList<>( list ) ); } String[] settings = user.getSettings(); if ( settings != null ) { 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 b822f3a61d..4d5e10547b 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 @@ -24,7 +24,7 @@ public Set convert(Stream source) { return null; } - Set set = new LinkedHashSet(); + Set set = new LinkedHashSet<>(); set.addAll( source.map( source1 -> convert( source1 ) ) .collect( Collectors.toCollection( LinkedHashSet::new ) ) 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 index 47baa689c8..3ded8ca7bf 100644 --- 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 @@ -72,7 +72,7 @@ protected Map stringContainerBeanMapToStringContainerB return null; } - Map map1 = new LinkedHashMap( 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() ) { String key = entry.getKey(); 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 22fed55509..5abb16122c 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 @@ -30,21 +30,21 @@ public Domain create(DtoWithPresenceCheck source) { if ( source.hasStrings() ) { List list = source.getStrings(); - domain.setStrings( new LinkedHashSet( list ) ); + 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 ) ); + 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 ) ); + domain.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { domain.setStringsWithDefault( helper.toList( "3" ) ); @@ -68,7 +68,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStrings() ) { List list = source.getStrings(); - target.setStrings( new LinkedHashSet( 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 LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -117,7 +117,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStringsWithDefault() ) { List list2 = source.getStringsWithDefault(); - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -140,7 +140,7 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStrings() ) { List list = source.getStrings(); - target.setStrings( new LinkedHashSet( 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 LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -189,7 +189,7 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStringsWithDefault() ) { List list2 = source.getStringsWithDefault(); - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -204,7 +204,7 @@ protected Set stringListToLongSet(List list) { return null; } - Set set = new LinkedHashSet( 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 87d2fccb26..2dbdf353a2 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 @@ -28,17 +28,17 @@ public Domain create(Dto source) { if ( source != null ) { List list = source.getStrings(); if ( list != null ) { - domain.setStrings( new LinkedHashSet( list ) ); + domain.setStrings( new LinkedHashSet<>( list ) ); } domain.setLongs( stringListToLongSet( source.getStrings() ) ); List list1 = source.getStringsInitialized(); if ( list1 != null ) { - domain.setStringsInitialized( new LinkedHashSet( list1 ) ); + domain.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - domain.setStringsWithDefault( new ArrayList( list2 ) ); + domain.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { domain.setStringsWithDefault( helper.toList( "3" ) ); @@ -59,16 +59,16 @@ public void update(Dto source, Domain target) { target.getStrings().addAll( list ); } else { - target.setStrings( new LinkedHashSet() ); + target.setStrings( new LinkedHashSet<>() ); } } else { List list = source.getStrings(); if ( list != null ) { - target.setStrings( new LinkedHashSet( list ) ); + target.setStrings( new LinkedHashSet<>( list ) ); } else { - target.setStrings( new LinkedHashSet() ); + target.setStrings( new LinkedHashSet<>() ); } } if ( target.getLongs() != null ) { @@ -78,7 +78,7 @@ public void update(Dto source, Domain target) { target.getLongs().addAll( set ); } else { - target.setLongs( new LinkedHashSet() ); + target.setLongs( new LinkedHashSet<>() ); } } else { @@ -87,7 +87,7 @@ public void update(Dto source, Domain target) { target.setLongs( set ); } else { - target.setLongs( new LinkedHashSet() ); + target.setLongs( new LinkedHashSet<>() ); } } if ( target.getStringsInitialized() != null ) { @@ -97,16 +97,16 @@ public void update(Dto source, Domain target) { target.getStringsInitialized().addAll( list1 ); } else { - target.setStringsInitialized( new LinkedHashSet() ); + target.setStringsInitialized( new LinkedHashSet<>() ); } } else { List list1 = source.getStringsInitialized(); if ( list1 != null ) { - target.setStringsInitialized( new LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } else { - target.setStringsInitialized( new LinkedHashSet() ); + target.setStringsInitialized( new LinkedHashSet<>() ); } } if ( target.getLongsInitialized() != null ) { @@ -116,7 +116,7 @@ public void update(Dto source, Domain target) { target.getLongsInitialized().addAll( set1 ); } else { - target.setLongsInitialized( new LinkedHashSet() ); + target.setLongsInitialized( new LinkedHashSet<>() ); } } else { @@ -125,7 +125,7 @@ public void update(Dto source, Domain target) { target.setLongsInitialized( set1 ); } else { - target.setLongsInitialized( new LinkedHashSet() ); + target.setLongsInitialized( new LinkedHashSet<>() ); } } if ( target.getStringsWithDefault() != null ) { @@ -141,7 +141,7 @@ public void update(Dto source, Domain target) { else { List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -161,16 +161,16 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getStrings().addAll( list ); } else { - target.setStrings( new LinkedHashSet() ); + target.setStrings( new LinkedHashSet<>() ); } } else { List list = source.getStrings(); if ( list != null ) { - target.setStrings( new LinkedHashSet( list ) ); + target.setStrings( new LinkedHashSet<>( list ) ); } else { - target.setStrings( new LinkedHashSet() ); + target.setStrings( new LinkedHashSet<>() ); } } if ( target.getLongs() != null ) { @@ -180,7 +180,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getLongs().addAll( set ); } else { - target.setLongs( new LinkedHashSet() ); + target.setLongs( new LinkedHashSet<>() ); } } else { @@ -189,7 +189,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.setLongs( set ); } else { - target.setLongs( new LinkedHashSet() ); + target.setLongs( new LinkedHashSet<>() ); } } if ( target.getStringsInitialized() != null ) { @@ -199,16 +199,16 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getStringsInitialized().addAll( list1 ); } else { - target.setStringsInitialized( new LinkedHashSet() ); + target.setStringsInitialized( new LinkedHashSet<>() ); } } else { List list1 = source.getStringsInitialized(); if ( list1 != null ) { - target.setStringsInitialized( new LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } else { - target.setStringsInitialized( new LinkedHashSet() ); + target.setStringsInitialized( new LinkedHashSet<>() ); } } if ( target.getLongsInitialized() != null ) { @@ -218,7 +218,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getLongsInitialized().addAll( set1 ); } else { - target.setLongsInitialized( new LinkedHashSet() ); + target.setLongsInitialized( new LinkedHashSet<>() ); } } else { @@ -227,7 +227,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.setLongsInitialized( set1 ); } else { - target.setLongsInitialized( new LinkedHashSet() ); + target.setLongsInitialized( new LinkedHashSet<>() ); } } if ( target.getStringsWithDefault() != null ) { @@ -243,7 +243,7 @@ public Domain updateWithReturn(Dto source, Domain target) { else { List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -256,10 +256,10 @@ public Domain updateWithReturn(Dto source, Domain target) { protected Set stringListToLongSet(List list) { if ( list == null ) { - return new LinkedHashSet(); + return new LinkedHashSet<>(); } - Set set = new LinkedHashSet( 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 e257ac8443..225c002489 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 @@ -30,17 +30,17 @@ public Domain create(Dto source) { List list = source.getStrings(); if ( list != null ) { - domain.setStrings( new LinkedHashSet( list ) ); + domain.setStrings( new LinkedHashSet<>( list ) ); } domain.setLongs( stringListToLongSet( source.getStrings() ) ); List list1 = source.getStringsInitialized(); if ( list1 != null ) { - domain.setStringsInitialized( new LinkedHashSet( list1 ) ); + domain.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - domain.setStringsWithDefault( new ArrayList( list2 ) ); + domain.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { domain.setStringsWithDefault( helper.toList( "3" ) ); @@ -68,7 +68,7 @@ public void update(Dto source, Domain target) { else { List list = source.getStrings(); if ( list != null ) { - target.setStrings( new LinkedHashSet( 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 LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -132,7 +132,7 @@ public void update(Dto source, Domain target) { else { List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -159,7 +159,7 @@ public Domain updateWithReturn(Dto source, Domain target) { else { List list = source.getStrings(); if ( list != null ) { - target.setStrings( new LinkedHashSet( 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 LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -223,7 +223,7 @@ public Domain updateWithReturn(Dto source, Domain target) { else { List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -238,7 +238,7 @@ protected Set stringListToLongSet(List list) { return null; } - Set set = new LinkedHashSet( 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 ddba54dbd1..856fb4eb0a 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 @@ -30,21 +30,21 @@ public Domain create(DtoWithPresenceCheck source) { if ( source.hasStrings() ) { List list = source.getStrings(); - domain.setStrings( new LinkedHashSet( list ) ); + 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 ) ); + 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 ) ); + domain.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { domain.setStringsWithDefault( helper.toList( "3" ) ); @@ -68,7 +68,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStrings() ) { List list = source.getStrings(); - target.setStrings( new LinkedHashSet( 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 LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -117,7 +117,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStringsWithDefault() ) { List list2 = source.getStringsWithDefault(); - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -140,7 +140,7 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStrings() ) { List list = source.getStrings(); - target.setStrings( new LinkedHashSet( 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 LinkedHashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet<>( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -189,7 +189,7 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStringsWithDefault() ) { List list2 = source.getStringsWithDefault(); - target.setStringsWithDefault( new ArrayList( list2 ) ); + target.setStringsWithDefault( new ArrayList<>( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -204,7 +204,7 @@ protected Set stringListToLongSet(List list) { return null; } - Set set = new LinkedHashSet( 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 d9e60ad1e1..ca076cb5aa 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 @@ -68,7 +68,7 @@ public List sourceFoosToTargetFoos(List foos) { return null; } - List list = new ArrayList( foos.size() ); + List list = new ArrayList<>( foos.size() ); for ( SourceFoo sourceFoo : foos ) { list.add( sourceFooToTargetFoo( sourceFoo ) ); } @@ -82,7 +82,7 @@ public Set sourceFoosToTargetFoos(Set foos) { return null; } - Set set = new LinkedHashSet( 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 ) ); } @@ -96,7 +96,7 @@ public Collection sourceFoosToTargetFoos(Collection foos) return null; } - Collection collection = new ArrayList( foos.size() ); + Collection collection = new ArrayList<>( foos.size() ); for ( SourceFoo sourceFoo : foos ) { collection.add( sourceFooToTargetFoo( sourceFoo ) ); } @@ -110,7 +110,7 @@ public Iterable sourceFoosToTargetFoos(Iterable foos) { return null; } - ArrayList iterable = new ArrayList(); + ArrayList iterable = new ArrayList<>(); for ( SourceFoo sourceFoo : foos ) { iterable.add( sourceFooToTargetFoo( sourceFoo ) ); } @@ -150,7 +150,7 @@ public SortedSet sourceFoosToTargetFooSortedSet(Collection return null; } - SortedSet sortedSet = new TreeSet(); + SortedSet sortedSet = new TreeSet<>(); for ( SourceFoo sourceFoo : foos ) { sortedSet.add( sourceFooToTargetFoo( sourceFoo ) ); } @@ -164,7 +164,7 @@ public NavigableSet sourceFoosToTargetFooNavigableSet(Collection navigableSet = new TreeSet(); + NavigableSet navigableSet = new TreeSet<>(); for ( SourceFoo sourceFoo : foos ) { navigableSet.add( sourceFooToTargetFoo( sourceFoo ) ); } @@ -178,7 +178,7 @@ public Map sourceFooMapToTargetFooMap(Map fo return null; } - Map map = new LinkedHashMap( 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() ); @@ -195,7 +195,7 @@ public SortedMap sourceFooMapToTargetFooSortedMap(Map sortedMap = new TreeMap(); + SortedMap sortedMap = new TreeMap<>(); for ( java.util.Map.Entry entry : foos.entrySet() ) { String key = String.valueOf( entry.getKey() ); @@ -212,7 +212,7 @@ public NavigableMap sourceFooMapToTargetFooNavigableMap(Map navigableMap = new TreeMap(); + NavigableMap navigableMap = new TreeMap<>(); for ( java.util.Map.Entry entry : foos.entrySet() ) { String key = String.valueOf( entry.getKey() ); @@ -229,7 +229,7 @@ public ConcurrentMap sourceFooMapToTargetFooConcurrentMap(Map return null; } - ConcurrentMap concurrentMap = new ConcurrentHashMap( Math.max( (int) ( foos.size() / .75f ) + 1, 16 ) ); + 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() ); @@ -246,7 +246,7 @@ public ConcurrentNavigableMap sourceFooMapToTargetFooConcurre return null; } - ConcurrentNavigableMap concurrentNavigableMap = new ConcurrentSkipListMap(); + ConcurrentNavigableMap concurrentNavigableMap = new ConcurrentSkipListMap<>(); 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/conversion/numbers/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapperImpl.java index 4fd0044c54..07fa6ebefc 100644 --- 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 @@ -357,7 +357,7 @@ public List sourceToTarget(List source) { return null; } - List list = new ArrayList( source.size() ); + List list = new ArrayList<>( source.size() ); for ( Float float1 : source ) { list.add( new DecimalFormat( "##.00" ).format( float1 ) ); } @@ -371,7 +371,7 @@ public List targetToSource(List source) { return null; } - List list = new ArrayList( source.size() ); + List list = new ArrayList<>( source.size() ); for ( String string : source ) { try { list.add( new DecimalFormat( "##.00" ).parse( string ).floatValue() ); @@ -390,7 +390,7 @@ public List sourceToTargetWithCustomLocale(List source) { return null; } - List list = new ArrayList( source.size() ); + List list = new ArrayList<>( source.size() ); for ( BigDecimal bigDecimal : source ) { list.add( createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "fr" ) ).format( bigDecimal ) ); } @@ -404,7 +404,7 @@ public List targetToSourceWithCustomLocale(List source) { return null; } - List list = new ArrayList( source.size() ); + List list = new ArrayList<>( source.size() ); for ( String string : source ) { try { list.add( (BigDecimal) createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "fr" ) ).parse( string ) ); @@ -423,7 +423,7 @@ public Map sourceToTarget(Map source) { return null; } - Map map = new LinkedHashMap( Math.max( (int) ( source.size() / .75f ) + 1, 16 ) ); + 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() ); @@ -440,7 +440,7 @@ public Map sourceToTargetWithCustomLocale(Map map = new LinkedHashMap( Math.max( (int) ( source.size() / .75f ) + 1, 16 ) ); + 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() ); @@ -457,7 +457,7 @@ public Map targetToSource(Map source) { return null; } - Map map = new LinkedHashMap( Math.max( (int) ( source.size() / .75f ) + 1, 16 ) ); + Map map = new LinkedHashMap<>( Math.max( (int) ( source.size() / .75f ) + 1, 16 ) ); for ( java.util.Map.Entry entry : source.entrySet() ) { Float key; @@ -486,7 +486,7 @@ public Map targetToSourceWithCustomLocale(Map map = new LinkedHashMap( Math.max( (int) ( source.size() / .75f ) + 1, 16 ) ); + Map map = new LinkedHashMap<>( Math.max( (int) ( source.size() / .75f ) + 1, 16 ) ); for ( java.util.Map.Entry entry : source.entrySet() ) { BigDecimal key; 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 index 7dab330793..daf5fcc2e5 100644 --- 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 @@ -24,7 +24,7 @@ public List map(List list) { return null; } - List list1 = new ArrayList( list.size() ); + List list1 = new ArrayList<>( list.size() ); for ( Source source : list ) { list1.add( instanceMapper.map( source ) ); } 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 index 3854376bad..1e973cba35 100644 --- 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 @@ -25,7 +25,7 @@ public List map(List list) { return null; } - List list1 = new ArrayList( list.size() ); + List list1 = new ArrayList<>( list.size() ); for ( Source source : list ) { list1.add( nonInstanceMapper.map( source ) ); } 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 index 4cca04617a..3f9bb581ad 100644 --- 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 @@ -25,7 +25,7 @@ public List map(List list) { return null; } - List list1 = new ArrayList( list.size() ); + List list1 = new ArrayList<>( list.size() ); for ( Source source : list ) { list1.add( nonPublicMapper.map( source ) ); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/generics/wildcard/BoundCopyMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/generics/wildcard/BoundCopyMapperImpl.java new file mode 100644 index 0000000000..2013985996 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/generics/wildcard/BoundCopyMapperImpl.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.generics.wildcard; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2026-03-30T02:05:36+0200", + comments = "version: , compiler: javac, environment: Java 21.0.5 (Eclipse Adoptium)" +) +public class BoundCopyMapperImpl implements BoundCopyMapper { + + @Override + public CollectionSuperTypes copySuperCollection(CollectionSuperTypes collectionSuperTypes) { + if ( collectionSuperTypes == null ) { + return null; + } + + CollectionSuperTypes collectionSuperTypes1 = new CollectionSuperTypes(); + + Collection collection = collectionSuperTypes.getSimpleObjectsCollection(); + if ( collection != null ) { + collectionSuperTypes1.setSimpleObjectsCollection( new ArrayList<>( collection ) ); + } + + return collectionSuperTypes1; + } + + @Override + public CollectionExtendTypes copyExtendsCollection(CollectionExtendTypes collectionExtendTypes) { + if ( collectionExtendTypes == null ) { + return null; + } + + CollectionExtendTypes collectionExtendTypes1 = new CollectionExtendTypes(); + + Collection collection = collectionExtendTypes.getSimpleObjectsCollection(); + if ( collection != null ) { + collectionExtendTypes1.setSimpleObjectsCollection( new ArrayList<>( collection ) ); + } + + return collectionExtendTypes1; + } + + @Override + public MapSuperType copySuperMap(MapSuperType mapSuperType) { + if ( mapSuperType == null ) { + return null; + } + + MapSuperType mapSuperType1 = new MapSuperType(); + + Map map = mapSuperType.getSimpleMap(); + if ( map != null ) { + mapSuperType1.setSimpleMap( new LinkedHashMap<>( map ) ); + } + + return mapSuperType1; + } + + @Override + public MapExtendType copyExtendMap(MapExtendType mapExtendType) { + if ( mapExtendType == null ) { + return null; + } + + MapExtendType mapExtendType1 = new MapExtendType(); + + Map map = mapExtendType.getSimpleMap(); + if ( map != null ) { + mapExtendType1.setSimpleMap( new LinkedHashMap<>( map ) ); + } + + return mapExtendType1; + } +} 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 4954a9163b..a2379260de 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 @@ -82,7 +82,7 @@ public List mapWheels(List wheels) { return null; } - List list = new ArrayList( wheels.size() ); + 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 e29d0bccf7..154d4f0426 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 @@ -65,7 +65,7 @@ protected List wheelListToWheelDtoList(List list) { return null; } - List list1 = new ArrayList( list.size() ); + List list1 = new ArrayList<>( list.size() ); for ( Wheel wheel : list ) { list1.add( wheelToWheelDto( wheel ) ); } @@ -152,7 +152,7 @@ protected List wheelListToWhee return null; } - List list1 = new ArrayList( list.size() ); + 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 548d236e57..dc099afee1 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 @@ -75,7 +75,7 @@ protected List wheelListToWheelDtoList(List list) { return null; } - List list1 = new ArrayList( list.size() ); + 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 5eff50e342..49aa5e338c 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 @@ -83,7 +83,7 @@ protected Map secretaryDtoEmployeeDtoMapToSecre return null; } - Map map1 = new LinkedHashMap( 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 1f21f0f637..e5b6ba089f 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 @@ -33,7 +33,7 @@ public void toDepartmentEntity(DepartmentDto dto, DepartmentEntity entity) { entity.setName( dto.getName() ); if ( dto.getEmployees() != null ) { if ( entity.getEmployees() == null ) { - entity.setEmployees( new ArrayList() ); + entity.setEmployees( new ArrayList<>() ); } externalHandWrittenMapper.toEmployeeEntityList( dto.getEmployees(), entity.getEmployees() ); } @@ -42,7 +42,7 @@ public void toDepartmentEntity(DepartmentDto dto, DepartmentEntity entity) { } if ( dto.getSecretaryToEmployee() != null ) { if ( entity.getSecretaryToEmployee() == null ) { - entity.setSecretaryToEmployee( new LinkedHashMap() ); + entity.setSecretaryToEmployee( new LinkedHashMap<>() ); } externalHandWrittenMapper.toSecretaryEmployeeEntityMap( dto.getSecretaryToEmployee(), entity.getSecretaryToEmployee() ); }