- AutoMapper 注解增加 mapperName 属性,支持可以自定义生成转换接口名称;

- AutoMapper 注解增加 mapperNameSuffix 属性,支持配置生成的转换接口名称增加后缀,默认规则下生成的反向转换接口同时生效;
- 适配 Mapper 注解的 unmappedSourcePolicy、unmappedTargetPolicy、typeConversionPolicy、collectionMappingStrategy、nullValueMappingStrategy、nullValueIterableMappingStrategy、nullValuePropertyMappingStrategy、nullValueCheckStrategy、mappingControl 属性
- 适配 Mapping 注解的 constant、qualifiedBy、nullValueCheckStrategy、nullValuePropertyMappingStrategy、mappingControl
- 适配 MapStruct 配置的 typeConversionPolicy、collectionMappingStrategy、nullValueIterableMappingStrategy、nullValueMapMappingStrategy、nullValueCheckStrategy、mappingControl、unexpectedValueMappingException、suppressTimestampInGenerated 属性
- 优化转换接口生成逻辑
- 适配同一模块中同类不同包生成类名冲突的问题
- 优化生成反向转换逻辑的默认规则,当原规则的 source 中存在 . 时,不生成相应的反向转换规则;
- 修复 targetClass 同时配置父类和子类时,转换规则冲突的问题
- 修复不同模块配置类、代理类类名冲突的问题
- 增加用例
This commit is contained in:
linpeilie 2024-05-24 18:52:26 +08:00
parent bc6a6be078
commit be2d80aebe
337 changed files with 15216 additions and 311 deletions

View File

@ -21,6 +21,7 @@
<mapstruct-plus.version>1.4.1-SNAPSHOT</mapstruct-plus.version> <mapstruct-plus.version>1.4.1-SNAPSHOT</mapstruct-plus.version>
<lombok.version>1.18.22</lombok.version> <lombok.version>1.18.22</lombok.version>
<hutool.version>5.8.26</hutool.version> <hutool.version>5.8.26</hutool.version>
<guava.version>32.1.3-jre</guava.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@ -50,6 +51,11 @@
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
<version>${hutool.version}</version> <version>${hutool.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

View File

@ -50,6 +50,10 @@
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -1,12 +1,14 @@
package io.github.linpeilie; package io.github.linpeilie;
import io.github.linpeilie.annotations.MapperConfig; import io.github.linpeilie.annotations.MapperConfig;
import org.mapstruct.Builder;
@MapperConfig(adapterClassName = "DemoConvertMapperAdapter", @MapperConfig(adapterClassName = "DemoConvertMapperAdapter",
adapterPackage = "io.github.linpeilie.adapter", adapterPackage = "io.github.linpeilie.adapter",
mapAdapterClassName = "DemoMapConvertMapperAdapter", mapAdapterClassName = "DemoMapConvertMapperAdapter",
autoConfigPackage = "cn.easii", autoConfigPackage = "cn.easii",
autoMapperConfigClassName = "EasiiAutoMapperConfig", autoMapperConfigClassName = "EasiiAutoMapperConfig",
autoMapMapperConfigClassName = "EasiiAutoMapMapperConfig") autoMapMapperConfigClassName = "EasiiAutoMapMapperConfig",
builder = @Builder(disableBuilder = false))
public class MapStructPlusConfiguration { public class MapStructPlusConfiguration {
} }

View File

@ -13,6 +13,9 @@ public class Titles {
if ("One Hundred Years of Solitude".equals(title)) { if ("One Hundred Years of Solitude".equals(title)) {
return "Cent ans de solitude"; return "Cent ans de solitude";
} }
if ("Default".equals(title)) {
return null;
}
return "Inconnu et inconnu"; return "Inconnu et inconnu";
} }

View File

@ -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 io.github.linpeilie.me;
/**
* @author Filip Hrisafov
*/
public class NoProperties {
}

View File

@ -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 io.github.linpeilie.me;
import io.github.linpeilie.annotations.AutoMapper;
/**
* @author Filip Hrisafov
*/
@AutoMapper(target = NoProperties.class)
public class WithProperties {
private String string;
public String getString() {
return string;
}
public void setString(String string) {
this.string = string;
}
}

View File

@ -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 io.github.linpeilie.me.array;
import io.github.linpeilie.annotations.AutoMapper;
@AutoMapper(target = ScientistDto.class)
public class Scientist {
//CHECKSTYLE:OFF
public String[] publicPublications;
public String[] publicPublicationYears;
//CHECKSTYLE:ON
private String name;
private String[] publications;
private String[] publicationYears;
public Scientist(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String[] getPublications() {
return publications;
}
public void setPublications(String[] publications) {
this.publications = publications;
}
public String[] getPublicationYears() {
return publicationYears;
}
public void setPublicationYears(String[] publicationYears) {
this.publicationYears = publicationYears;
}
}

View File

@ -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 io.github.linpeilie.me.array;
public class ScientistDto {
//CHECKSTYLE:OFF
public String[] publicPublications;
public int[] publicPublicationYears;
//CHECKSTYLE:ON
private String name;
private String[] publications;
private int[] publicationYears;
public ScientistDto() {
}
public ScientistDto(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String[] getPublications() {
return publications;
}
public void setPublications(String[] publications) {
this.publications = publications;
}
public int[] getPublicationYears() {
return publicationYears;
}
public void setPublicationYears(int[] publicationYears) {
this.publicationYears = publicationYears;
}
}

View File

@ -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 io.github.linpeilie.me.bool;
import io.github.linpeilie.annotations.AutoMapper;
@AutoMapper(target = PersonDto.class, uses = YesNoMapper.class, reverseConvertGenerate = false)
public class Person {
private Boolean married;
private Boolean engaged;
private YesNo divorced;
private YesNo widowed;
public Boolean isMarried() {
return married;
}
public void setMarried(Boolean married) {
this.married = married;
}
// START: please note: deliberately ordered, first getEngaged, then isEngaged.
public Boolean getEngaged() {
return engaged;
}
public Boolean isEngaged() {
return engaged != null && !engaged;
}
// END
public void setEngaged(Boolean engaged) {
this.engaged = engaged;
}
public YesNo getDivorced() {
return divorced;
}
public void setDivorced(YesNo divorced) {
this.divorced = divorced;
}
public YesNo getWidowed() {
return widowed;
}
public void setWidowed(YesNo widowed) {
this.widowed = widowed;
}
}

View File

@ -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 io.github.linpeilie.me.bool;
public class PersonDto {
private String married;
private String engaged;
private String divorced;
private Boolean widowed;
public String getMarried() {
return married;
}
public void setMarried(String married) {
this.married = married;
}
public String getEngaged() {
return engaged;
}
public void setEngaged(String engaged) {
this.engaged = engaged;
}
public String getDivorced() {
return divorced;
}
public void setDivorced(String divorced) {
this.divorced = divorced;
}
public Boolean getWidowed() {
return widowed;
}
public void setWidowed(Boolean widowed) {
this.widowed = widowed;
}
}

View File

@ -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 io.github.linpeilie.me.bool;
/**
* @author Andreas Gudian
*
*/
public class YesNo {
private boolean yes;
public YesNo(boolean yes) {
this.yes = yes;
}
public boolean isYes() {
return yes;
}
public void setYes(boolean yes) {
this.yes = yes;
}
}

View File

@ -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 io.github.linpeilie.me.bool;
import org.mapstruct.Mapper;
import org.springframework.stereotype.Component;
/**
* @author Andreas Gudian
*
*/
@Component
public class YesNoMapper {
public String toString(YesNo yesNo) {
if ( null != yesNo && yesNo.isYes() ) {
return "yes";
}
return "no";
}
public boolean toBool(YesNo yesNo) {
return ( null != yesNo && yesNo.isYes() );
}
}

View File

@ -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 io.github.linpeilie.me.builder.abstractBuilder;
/**
* @author Filip Hrisafov
*/
public abstract class AbstractImmutableProduct {
private final String name;
public AbstractImmutableProduct(AbstractProductBuilder<?> builder) {
this.name = builder.name;
}
public String getName() {
return name;
}
}

View File

@ -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 io.github.linpeilie.me.builder.abstractBuilder;
public abstract class AbstractProductBuilder<T extends AbstractImmutableProduct> {
protected String name;
public AbstractProductBuilder<T> name(String name) {
this.name = name;
return this;
}
public abstract T build();
}

View File

@ -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 io.github.linpeilie.me.builder.abstractBuilder;
public class ImmutableProduct extends AbstractImmutableProduct {
private final Integer price;
public ImmutableProduct(ImmutableProductBuilder builder) {
super( builder );
this.price = builder.price;
}
public static ImmutableProductBuilder builder() {
return new ImmutableProductBuilder();
}
public Integer getPrice() {
return price;
}
public static class ImmutableProductBuilder extends AbstractProductBuilder<ImmutableProduct> {
private Integer price;
public ImmutableProductBuilder price(Integer price) {
this.price = price;
return this;
}
@Override
public ImmutableProduct build() {
return new ImmutableProduct( this );
}
}
}

View File

@ -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 io.github.linpeilie.me.builder.abstractBuilder;
import io.github.linpeilie.annotations.AutoMapper;
@AutoMapper(target = ImmutableProduct.class)
public class ProductDto {
private String name;
private Integer price;
public ProductDto() {
}
public ProductDto(String name, Integer price) {
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
}

View File

@ -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 io.github.linpeilie.me.builder.abstractGenericTarget;
public interface Child {
String getName();
}

View File

@ -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 io.github.linpeilie.me.builder.abstractGenericTarget;
import io.github.linpeilie.annotations.AutoMapper;
@AutoMapper(target = ImmutableChild.class)
public class ChildSource {
private String name;
public ChildSource() {
}
public ChildSource(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -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 io.github.linpeilie.me.builder.abstractGenericTarget;
public class ImmutableChild implements Child {
private final String name;
private ImmutableChild(Builder builder) {
this.name = builder.name;
}
public static Builder builder() {
return new Builder();
}
public String getName() {
return name;
}
public static class Builder {
private String name;
public Builder name(String name) {
this.name = name;
return this;
}
public ImmutableChild build() {
return new ImmutableChild( this );
}
}
}

View File

@ -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 io.github.linpeilie.me.builder.abstractGenericTarget;
public class ImmutableParent implements Parent<ImmutableChild> {
private final int count;
private final ImmutableChild child;
private final Child nonGenericChild;
public ImmutableParent(Builder builder) {
this.count = builder.count;
this.child = builder.child;
this.nonGenericChild = builder.nonGenericChild;
}
public static Builder builder() {
return new Builder();
}
@Override
public Child getNonGenericChild() {
return nonGenericChild;
}
@Override
public int getCount() {
return count;
}
@Override
public ImmutableChild getChild() {
return child;
}
public static class Builder {
private int count;
private ImmutableChild child;
private Child nonGenericChild;
public Builder count(int count) {
this.count = count;
return this;
}
public Builder nonGenericChild(Child nonGenericChild) {
this.nonGenericChild = nonGenericChild;
return this;
}
public Builder child(ImmutableChild child) {
this.child = child;
return this;
}
public ImmutableParent build() {
return new ImmutableParent( this );
}
}
}

View File

@ -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 io.github.linpeilie.me.builder.abstractGenericTarget;
public class MutableChild implements Child {
private String name;
@Override
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -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 io.github.linpeilie.me.builder.abstractGenericTarget;
public class MutableParent implements Parent<ImmutableChild> {
private int count;
private ImmutableChild child;
private Child nonGenericChild;
@Override
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
@Override
public ImmutableChild getChild() {
return child;
}
public void setChild(ImmutableChild child) {
this.child = child;
}
@Override
public Child getNonGenericChild() {
return nonGenericChild;
}
public void setNonGenericChild(Child nonGenericChild) {
this.nonGenericChild = nonGenericChild;
}
}

View File

@ -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 io.github.linpeilie.me.builder.abstractGenericTarget;
public interface Parent<T extends Child> {
int getCount();
T getChild();
Child getNonGenericChild();
}

View File

@ -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 io.github.linpeilie.me.builder.abstractGenericTarget;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMappers;
@AutoMappers({
@AutoMapper(target = ImmutableParent.class),
@AutoMapper(target = MutableParent.class)
})
public class ParentSource {
private int count;
private ChildSource child;
private ChildSource nonGenericChild;
public ChildSource getNonGenericChild() {
return nonGenericChild;
}
public void setNonGenericChild(ChildSource nonGenericChild) {
this.nonGenericChild = nonGenericChild;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public ChildSource getChild() {
return child;
}
public void setChild(ChildSource child) {
this.child = child;
}
}

View File

@ -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 io.github.linpeilie.me.builder.factory;
import org.mapstruct.Mapper;
import org.mapstruct.ObjectFactory;
import org.mapstruct.factory.Mappers;
import org.springframework.stereotype.Component;
/**
* @author Filip Hrisafov
*/
@Component
public class BuilderFactoryMapper {
@ObjectFactory
public Person.PersonBuilder personBuilder() {
return new Person.PersonBuilder( "Factory with @ObjectFactory" );
}
}

View File

@ -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 io.github.linpeilie.me.builder.factory;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import org.springframework.stereotype.Component;
/**
* @author Filip Hrisafov
*/
@Component
public class BuilderImplicitFactoryMapper {
public ImplicitPerson.PersonBuilder personBuilder() {
return new ImplicitPerson.PersonBuilder("Implicit Factory");
}
}

View File

@ -0,0 +1,43 @@
package io.github.linpeilie.me.builder.factory;
public class ImplicitPerson {
private final String name;
private final String source;
protected ImplicitPerson(ImplicitPerson.PersonBuilder builder) {
this.name = builder.name;
this.source = builder.source;
}
public String getName() {
return name;
}
public String getSource() {
return source;
}
public static ImplicitPerson.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 ImplicitPerson.PersonBuilder name(String name) {
this.name = name;
return this;
}
public ImplicitPerson build() {
return new ImplicitPerson( this );
}
}
}

View File

@ -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 io.github.linpeilie.me.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 build() {
return new Person( this );
}
}
}

View File

@ -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 io.github.linpeilie.me.builder.factory;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMappers;
/**
* @author Filip Hrisafov
*/
@AutoMappers({
@AutoMapper(target = Person.class, uses = BuilderFactoryMapper.class, reverseConvertGenerate = false),
@AutoMapper(target = ImplicitPerson.class, uses = BuilderImplicitFactoryMapper.class, reverseConvertGenerate = false),
})
public class PersonDto {
private String name;
public PersonDto(String name) {
this.name = name;
}
public String getName() {
return name;
}
}

View File

@ -0,0 +1,244 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.github.linpeilie.me.callbacks;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.mapstruct.AfterMapping;
import org.mapstruct.BeforeMapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.TargetType;
import org.springframework.stereotype.Component;
/**
* @author Andreas Gudian
*/
@Component
public class BaseMapper {
private static final List<Invocation> INVOCATIONS = new ArrayList<Invocation>();
@BeforeMapping
public void noArgsBeforeMapping() {
INVOCATIONS.add( new Invocation( "noArgsBeforeMapping" ) );
}
@BeforeMapping
public void withSourceBeforeMapping(Source source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
}
@BeforeMapping
@Qualified
public void withSourceBeforeMappingQualified(Source source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMappingQualified", source ) );
}
@BeforeMapping
public void withSourceBeforeMapping(SourceEnum source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
}
@BeforeMapping
public void withSourceBeforeMapping(List<Source> source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
}
@BeforeMapping
@Qualified
public void withSourceBeforeMappingQualified(List<Source> source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMappingQualified", source ) );
}
@BeforeMapping
public void withSourceBeforeMapping(Map<String, Source> source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
}
@BeforeMapping
@Qualified
public void withSourceBeforeMappingQualified(Map<String, Source> source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMappingQualified", source ) );
}
@BeforeMapping
public void withSourceAsObjectBeforeMapping(Object source) {
INVOCATIONS.add( new Invocation( "withSourceAsObjectBeforeMapping", source ) );
}
@BeforeMapping
public <T> void withSourceAndTargetTypeBeforeMapping(Source source, @TargetType Class<T> targetClass) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
}
@BeforeMapping
public <T> void withSourceAndTargetTypeBeforeMapping(SourceEnum source, @TargetType Class<T> targetClass) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
}
@BeforeMapping
public <T> void withSourceAndTargetTypeBeforeMapping(List<Source> source, @TargetType Class<T> targetClass) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
}
@BeforeMapping
public <T> void withSourceAndTargetTypeBeforeMapping(Map<String, Source> source, @TargetType Class<T> targetClass) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
}
@BeforeMapping
public void withSourceAndTargetBeforeMapping(Source source, @MappingTarget Target target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
}
@BeforeMapping
public void withSourceAndTargetBeforeMapping(SourceEnum source, @MappingTarget TargetEnum target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
}
@BeforeMapping
public void withSourceAndTargetBeforeMapping(List<Source> source, @MappingTarget List<Target> target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
}
@BeforeMapping
public void withSourceAndTargetBeforeMapping(Map<String, Source> source,
@MappingTarget Map<String, Target> target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
}
@BeforeMapping
public void withTargetBeforeMapping(@MappingTarget Target target) {
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
}
@BeforeMapping
public void withTargetBeforeMapping(@MappingTarget TargetEnum target) {
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
}
@BeforeMapping
public void withTargetBeforeMapping(@MappingTarget List<Target> target) {
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
}
@BeforeMapping
public void withTargetBeforeMapping(@MappingTarget Map<String, Target> target) {
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
}
@BeforeMapping
public void withTargetAsObjectBeforeMapping(@MappingTarget Object target) {
INVOCATIONS.add( new Invocation( "withTargetAsObjectBeforeMapping", target ) );
}
@AfterMapping
public void noArgsAfterMapping() {
INVOCATIONS.add( new Invocation( "noArgsAfterMapping" ) );
}
@AfterMapping
public void withSourceAfterMapping(Source source) {
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
}
@AfterMapping
public void withSourceAfterMapping(SourceEnum source) {
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
}
@AfterMapping
public void withSourceAfterMapping(List<Source> source) {
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
}
@AfterMapping
public void withSourceAfterMapping(Map<String, Source> source) {
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
}
@AfterMapping
public void withSourceAsObjectAfterMapping(Object source) {
INVOCATIONS.add( new Invocation( "withSourceAsObjectAfterMapping", source ) );
}
@AfterMapping
public void withSourceAndTargetAfterMapping(Source source, @MappingTarget Target target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
}
@AfterMapping
public void withSourceAndTargetAfterMapping(SourceEnum source, @MappingTarget TargetEnum target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
}
@AfterMapping
public void withSourceAndTargetAfterMapping(List<Source> source, @MappingTarget List<Target> target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
}
@AfterMapping
public void withSourceAndTargetAfterMapping(Map<String, Source> source, @MappingTarget Map<String, Target> target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
}
@AfterMapping
public void withTargetAfterMapping(@MappingTarget Target target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
}
@AfterMapping
public void withTargetAfterMapping(@MappingTarget TargetEnum target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
}
@AfterMapping
@Qualified
public void withTargetAfterMappingQualified(@MappingTarget Target target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMappingQualified", target ) );
}
@AfterMapping
public void withTargetAfterMapping(@MappingTarget List<Target> target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
}
@AfterMapping
@Qualified
public void withTargetAfterMappingQualified(@MappingTarget List<Target> target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMappingQualified", target ) );
}
@AfterMapping
public void withTargetAfterMapping(@MappingTarget Map<String, Target> target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
}
@AfterMapping
@Qualified
public void withTargetAfterMappingQualified(@MappingTarget Map<String, Target> target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMappingQualified", target ) );
}
@AfterMapping
public void withTargetAsObjectAfterMapping(@MappingTarget Object target) {
INVOCATIONS.add( new Invocation( "withTargetAsObjectAfterMapping", target ) );
}
@AfterMapping
public <T> void withTargetAndTargetTypeAfterMapping(@MappingTarget T target, @TargetType Class<T> targetClass) {
INVOCATIONS.add( new Invocation( "withTargetAndTargetTypeAfterMapping", target, targetClass ) );
}
public static List<Invocation> getInvocations() {
return INVOCATIONS;
}
public static void reset() {
INVOCATIONS.clear();
}
}

View File

@ -0,0 +1,243 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.github.linpeilie.me.callbacks;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.mapstruct.AfterMapping;
import org.mapstruct.BeforeMapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.TargetType;
import org.springframework.stereotype.Component;
/**
* @author Andreas Gudian
*/
@Component
public class ClassContainingCallbacks {
private static final List<Invocation> INVOCATIONS = new ArrayList<Invocation>();
@BeforeMapping
public void noArgsBeforeMapping() {
INVOCATIONS.add( new Invocation( "noArgsBeforeMapping" ) );
}
@BeforeMapping
public void withSourceBeforeMapping(Source source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
}
@BeforeMapping
@Qualified
public void withSourceBeforeMappingQualified(Source source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMappingQualified", source ) );
}
@BeforeMapping
public void withSourceBeforeMapping(SourceEnum source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
}
@BeforeMapping
public void withSourceBeforeMapping(List<Source> source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
}
@BeforeMapping
@Qualified
public void withSourceBeforeMappingQualified(List<Source> source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMappingQualified", source ) );
}
@BeforeMapping
public void withSourceBeforeMapping(Map<String, Source> source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
}
@BeforeMapping
@Qualified
public void withSourceBeforeMappingQualified(Map<String, Source> source) {
INVOCATIONS.add( new Invocation( "withSourceBeforeMappingQualified", source ) );
}
@BeforeMapping
public void withSourceAsObjectBeforeMapping(Object source) {
INVOCATIONS.add( new Invocation( "withSourceAsObjectBeforeMapping", source ) );
}
@BeforeMapping
public <T> void withSourceAndTargetTypeBeforeMapping(Source source, @TargetType Class<T> targetClass) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
}
@BeforeMapping
public <T> void withSourceAndTargetTypeBeforeMapping(SourceEnum source, @TargetType Class<T> targetClass) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
}
@BeforeMapping
public <T> void withSourceAndTargetTypeBeforeMapping(List<Source> source, @TargetType Class<T> targetClass) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
}
@BeforeMapping
public <T> void withSourceAndTargetTypeBeforeMapping(Map<String, Source> source, @TargetType Class<T> targetClass) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
}
@BeforeMapping
public void withSourceAndTargetBeforeMapping(Source source, @MappingTarget Target target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
}
@BeforeMapping
public void withSourceAndTargetBeforeMapping(SourceEnum source, @MappingTarget TargetEnum target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
}
@BeforeMapping
public void withSourceAndTargetBeforeMapping(List<Source> source, @MappingTarget List<Target> target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
}
@BeforeMapping
public void withSourceAndTargetBeforeMapping(Map<String, Source> source,
@MappingTarget Map<String, Target> target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
}
@BeforeMapping
public void withTargetBeforeMapping(@MappingTarget Target target) {
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
}
@BeforeMapping
public void withTargetBeforeMapping(@MappingTarget TargetEnum target) {
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
}
@BeforeMapping
public void withTargetBeforeMapping(@MappingTarget List<Target> target) {
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
}
@BeforeMapping
public void withTargetBeforeMapping(@MappingTarget Map<String, Target> target) {
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
}
@BeforeMapping
public void withTargetAsObjectBeforeMapping(@MappingTarget Object target) {
INVOCATIONS.add( new Invocation( "withTargetAsObjectBeforeMapping", target ) );
}
@AfterMapping
public void noArgsAfterMapping() {
INVOCATIONS.add( new Invocation( "noArgsAfterMapping" ) );
}
@AfterMapping
public void withSourceAfterMapping(Source source) {
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
}
@AfterMapping
public void withSourceAfterMapping(SourceEnum source) {
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
}
@AfterMapping
public void withSourceAfterMapping(List<Source> source) {
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
}
@AfterMapping
public void withSourceAfterMapping(Map<String, Source> source) {
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
}
@AfterMapping
public void withSourceAsObjectAfterMapping(Object source) {
INVOCATIONS.add( new Invocation( "withSourceAsObjectAfterMapping", source ) );
}
@AfterMapping
public void withSourceAndTargetAfterMapping(Source source, @MappingTarget Target target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
}
@AfterMapping
public void withSourceAndTargetAfterMapping(SourceEnum source, @MappingTarget TargetEnum target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
}
@AfterMapping
public void withSourceAndTargetAfterMapping(List<Source> source, @MappingTarget List<Target> target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
}
@AfterMapping
public void withSourceAndTargetAfterMapping(Map<String, Source> source, @MappingTarget Map<String, Target> target) {
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
}
@AfterMapping
public void withTargetAfterMapping(@MappingTarget Target target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
}
@AfterMapping
public void withTargetAfterMapping(@MappingTarget TargetEnum target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
}
@AfterMapping
@Qualified
public void withTargetAfterMappingQualified(@MappingTarget Target target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMappingQualified", target ) );
}
@AfterMapping
public void withTargetAfterMapping(@MappingTarget List<Target> target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
}
@AfterMapping
@Qualified
public void withTargetAfterMappingQualified(@MappingTarget List<Target> target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMappingQualified", target ) );
}
@AfterMapping
public void withTargetAfterMapping(@MappingTarget Map<String, Target> target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
}
@AfterMapping
@Qualified
public void withTargetAfterMappingQualified(@MappingTarget Map<String, Target> target) {
INVOCATIONS.add( new Invocation( "withTargetAfterMappingQualified", target ) );
}
@AfterMapping
public void withTargetAsObjectAfterMapping(@MappingTarget Object target) {
INVOCATIONS.add( new Invocation( "withTargetAsObjectAfterMapping", target ) );
}
@AfterMapping
public <T> void withTargetAndTargetTypeAfterMapping(@MappingTarget T target, @TargetType Class<T> targetClass) {
INVOCATIONS.add( new Invocation( "withTargetAndTargetTypeAfterMapping", target, targetClass ) );
}
public static List<Invocation> getInvocations() {
return INVOCATIONS;
}
public static void reset() {
INVOCATIONS.clear();
}
}

View File

@ -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 io.github.linpeilie.me.callbacks;
import java.util.Arrays;
/**
* @author Andreas Gudian
*/
public class Invocation {
private final String methodName;
private final String arguments;
public Invocation(String methodName, Object... arguments) {
this.methodName = methodName;
this.arguments = Arrays.toString( arguments );
}
public String getMethodName() {
return methodName;
}
public String getArguments() {
return arguments;
}
@Override
public String toString() {
return "Invocation [methodName=" + methodName + ", arguments=" + arguments + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ( ( arguments == null ) ? 0 : arguments.hashCode() );
result = prime * result + ( ( methodName == null ) ? 0 : methodName.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;
}
Invocation other = (Invocation) obj;
if ( arguments == null ) {
if ( other.arguments != null ) {
return false;
}
}
else if ( !arguments.equals( other.arguments ) ) {
return false;
}
if ( methodName == null ) {
return other.methodName == null;
}
else {
return methodName.equals( other.methodName );
}
}
}

View File

@ -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 io.github.linpeilie.me.callbacks;
import org.mapstruct.Qualifier;
/**
* @author Andreas Gudian
*
*/
@Qualifier
public @interface Qualified {
}

View File

@ -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 io.github.linpeilie.me.callbacks;
import io.github.linpeilie.annotations.AutoMapper;
/**
* @author Andreas Gudian
*/
@AutoMapper(target = Target.class, uses = {ClassContainingCallbacks.class, BaseMapper.class})
public class Source {
private String foo;
public String getFoo() {
return foo;
}
public void setFoo(String foo) {
this.foo = foo;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((foo == null) ? 0 : foo.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;
}
Source other = (Source) obj;
if (foo == null) {
return other.foo == null;
} else {
return foo.equals(other.foo);
}
}
@Override
public String toString() {
return "Source [foo=" + foo + "]";
}
}

View File

@ -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 io.github.linpeilie.me.callbacks;
/**
* @author Andreas Gudian
*
*/
public enum SourceEnum {
A, B, C;
}

View File

@ -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 io.github.linpeilie.me.callbacks;
/**
* @author Andreas Gudian
*/
public class Target {
private String foo;
public String getFoo() {
return foo;
}
public void setFoo(String foo) {
this.foo = foo;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ( ( foo == null ) ? 0 : foo.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;
}
Target other = (Target) obj;
if ( foo == null ) {
return other.foo == null;
}
else {
return foo.equals( other.foo );
}
}
@Override
public String toString() {
return "Target [foo=" + foo + "]";
}
}

View File

@ -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 io.github.linpeilie.me.callbacks;
/**
* @author Andreas Gudian
*
*/
public enum TargetEnum {
A, B, C;
}

View File

@ -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 io.github.linpeilie.me.callbacks.ongeneratedmethods;
import io.github.linpeilie.annotations.AutoMapper;
import org.mapstruct.ReportingPolicy;
/**
* @author Sjaak Derksen
*/
@AutoMapper(target = AddressDto.class, unmappedTargetPolicy = ReportingPolicy.IGNORE, uses = CompanyMapperPostProcessing.class)
public class Address {
private String addressLine;
private String town;
public String getAddressLine() {
return addressLine;
}
public void setAddressLine(String addressLine) {
this.addressLine = addressLine;
}
public String getTown() {
return town;
}
public void setTown(String town) {
this.town = town;
}
}

View File

@ -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 io.github.linpeilie.me.callbacks.ongeneratedmethods;
/**
*
* @author Sjaak Derksen
*/
public class AddressDto {
private int houseNumber;
private String street;
private String town;
public int getHouseNumber() {
return houseNumber;
}
public void setHouseNumber( int houseNumber ) {
this.houseNumber = houseNumber;
}
public String getStreet() {
return street;
}
public void setStreet( String street ) {
this.street = street;
}
public String getTown() {
return town;
}
public void setTown( String town ) {
this.town = town;
}
}

View File

@ -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 io.github.linpeilie.me.callbacks.ongeneratedmethods;
import io.github.linpeilie.annotations.AutoMapper;
import java.util.List;
import org.mapstruct.ReportingPolicy;
/**
* @author Sjaak Derksen
*/
@AutoMapper(target = CompanyDto.class, unmappedTargetPolicy = ReportingPolicy.IGNORE, uses = CompanyMapperPostProcessing.class)
public class Company {
private List<Employee> employees;
public List<Employee> getEmployees() {
return employees;
}
public void setEmployees(List<Employee> employees) {
this.employees = employees;
}
}

View File

@ -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 io.github.linpeilie.me.callbacks.ongeneratedmethods;
import java.util.List;
/**
*
* @author Sjaak Derksen
*/
public class CompanyDto {
private List<EmployeeDto> employees;
public List<EmployeeDto> getEmployees() {
return employees;
}
public void setEmployees( List<EmployeeDto> employees ) {
this.employees = employees;
}
}

View File

@ -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 io.github.linpeilie.me.callbacks.ongeneratedmethods;
import org.mapstruct.AfterMapping;
import org.mapstruct.MappingTarget;
import org.springframework.stereotype.Component;
/**
*
* @author Sjaak Derksen
*/
@Component
public class CompanyMapperPostProcessing {
@AfterMapping
public void toAddressDto(Address address, @MappingTarget AddressDto addressDto) {
String addressLine = address.getAddressLine();
int separatorIndex = addressLine.indexOf( ";" );
addressDto.setStreet( addressLine.substring( 0, separatorIndex ) );
String houseNumber = addressLine.substring( separatorIndex + 1 );
addressDto.setHouseNumber( Integer.parseInt( houseNumber ) );
}
}

View File

@ -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 io.github.linpeilie.me.callbacks.ongeneratedmethods;
import io.github.linpeilie.annotations.AutoMapper;
import org.mapstruct.ReportingPolicy;
/**
* @author Sjaak Derksen
*/
@AutoMapper(target = EmployeeDto.class, unmappedTargetPolicy = ReportingPolicy.IGNORE, uses = CompanyMapperPostProcessing.class, mapperNameSuffix = "$1")
public class Employee {
private Address address;
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}

View File

@ -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 io.github.linpeilie.me.callbacks.ongeneratedmethods;
/**
*
* @author Sjaak Derksen
*/
public class EmployeeDto {
private AddressDto address;
public AddressDto getAddress() {
return address;
}
public void setAddress( AddressDto address ) {
this.address = address;
}
}

View File

@ -0,0 +1,16 @@
package io.github.linpeilie.me.callbacks.typematching;
import io.github.linpeilie.annotations.AutoMapper;
@AutoMapper(target = CarEntity.class, uses = CarMapper.class)
public class CarDto extends Identifiable {
private int seatCount;
public int getSeatCount() {
return seatCount;
}
public void setSeatCount(int seatCount) {
this.seatCount = seatCount;
}
}

View File

@ -0,0 +1,13 @@
package io.github.linpeilie.me.callbacks.typematching;
public class CarEntity extends Identifiable {
private int seatCount;
public int getSeatCount() {
return seatCount;
}
public void setSeatCount(int seatCount) {
this.seatCount = seatCount;
}
}

View File

@ -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 io.github.linpeilie.me.callbacks.typematching;
import org.mapstruct.AfterMapping;
import org.mapstruct.BeforeMapping;
import org.mapstruct.MappingTarget;
import org.springframework.stereotype.Component;
/**
* @author Andreas Gudian
*/
@Component
public class CarMapper {
@AfterMapping
protected void neverMatched(ElectricCarDto electricDto) {
throw new RuntimeException("must not be called");
}
@AfterMapping
protected void neverMatched(@MappingTarget ElectricCarEntity electricEntity) {
throw new RuntimeException("must not be called");
}
@AfterMapping
protected void isCalled(@MappingTarget Object any) {
if (any instanceof CarEntity) {
CarEntity car = (CarEntity) any;
if (car.getSeatCount() == 0) {
car.setSeatCount(5);
}
}
}
@AfterMapping
protected void incrementsTargetId(@MappingTarget Identifiable identifiable) {
identifiable.setId(identifiable.getId() + 1);
}
@BeforeMapping
protected void incrementsSourceId(Identifiable identifiable) {
identifiable.setId(identifiable.getId() + 1);
}
}

View File

@ -0,0 +1,13 @@
package io.github.linpeilie.me.callbacks.typematching;
public class ElectricCarDto extends CarDto {
private long batteryCapacity;
public long getBatteryCapacity() {
return batteryCapacity;
}
public void setBatteryCapacity(long batteryCapacity) {
this.batteryCapacity = batteryCapacity;
}
}

View File

@ -0,0 +1,13 @@
package io.github.linpeilie.me.callbacks.typematching;
public class ElectricCarEntity extends Identifiable {
private long batteryCapacity;
public long getBatteryCapacity() {
return batteryCapacity;
}
public void setBatteryCapacity(long batteryCapacity) {
this.batteryCapacity = batteryCapacity;
}
}

View File

@ -0,0 +1,13 @@
package io.github.linpeilie.me.callbacks.typematching;
public abstract class Identifiable {
private long id;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}

View File

@ -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 io.github.linpeilie.me.collection;
public enum Colour {
RED, GREEN, BLUE;
}

View File

@ -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 io.github.linpeilie.me.collection;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMapping;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@AutoMapper(target = Target.class, uses = SourceTargetMapper.class)
public class Source {
private List<String> publicStringList;
private List<String> stringList;
private List<String> otherStringList;
private ArrayList<String> stringArrayList;
private Set<String> stringSet;
private HashSet<String> stringHashSet;
private Collection<String> stringCollection;
@AutoMapping(target = "integerCollection")
private List<Integer> integerList;
@AutoMapping(target = "set")
private Set<Integer> integerSet;
@AutoMapping(target = "anotherStringSet")
private Set<Integer> anotherIntegerSet;
private Set<Colour> colours;
private Map<String, Long> stringLongMap;
private Map<String, Long> otherStringLongMap;
@AutoMapping(target = "nonGenericMapStringtoLong")
private Map<String, Long> stringLongMapForNonGeneric;
@AutoMapping(target = "stringListNoSetter")
private List<String> stringList2;
@AutoMapping(target = "stringListNoSetter2")
private Set<String> stringSet2;
private EnumSet<Colour> enumSet;
@AutoMapping(target = "nonGenericStringList")
private List<String> stringList3;
public List<String> getPublicStringList() {
return publicStringList;
}
public void setPublicStringList(List<String> publicStringList) {
this.publicStringList = publicStringList;
}
public List<String> getStringList() {
return stringList;
}
public void setStringList(List<String> stringList) {
this.stringList = stringList;
}
public ArrayList<String> getStringArrayList() {
return stringArrayList;
}
public void setStringArrayList(ArrayList<String> stringArrayList) {
this.stringArrayList = stringArrayList;
}
public Set<String> getStringSet() {
return stringSet;
}
public void setStringSet(Set<String> stringSet) {
this.stringSet = stringSet;
}
public HashSet<String> getStringHashSet() {
return stringHashSet;
}
public void setStringHashSet(HashSet<String> stringHashSet) {
this.stringHashSet = stringHashSet;
}
public Collection<String> getStringCollection() {
return stringCollection;
}
public void setStringCollection(Collection<String> stringCollection) {
this.stringCollection = stringCollection;
}
public List<Integer> getIntegerList() {
return integerList;
}
public void setIntegerList(List<Integer> integerList) {
this.integerList = integerList;
}
public Set<Integer> getIntegerSet() {
return integerSet;
}
public void setIntegerSet(Set<Integer> integerSet) {
this.integerSet = integerSet;
}
public Set<Integer> getAnotherIntegerSet() {
return anotherIntegerSet;
}
public void setAnotherIntegerSet(Set<Integer> anotherIntegerSet) {
this.anotherIntegerSet = anotherIntegerSet;
}
public Set<Colour> getColours() {
return colours;
}
public void setColours(Set<Colour> colours) {
this.colours = colours;
}
public Map<String, Long> getStringLongMap() {
return stringLongMap;
}
public void setStringLongMap(Map<String, Long> stringLongMap) {
this.stringLongMap = stringLongMap;
}
public List<String> getStringList2() {
return stringList2;
}
public void setStringList2(List<String> stringList2) {
this.stringList2 = stringList2;
}
public List<String> getOtherStringList() {
return otherStringList;
}
public void setOtherStringList(List<String> otherStringList) {
this.otherStringList = otherStringList;
}
public Map<String, Long> getOtherStringLongMap() {
return otherStringLongMap;
}
public void setOtherStringLongMap(Map<String, Long> otherStringLongMap) {
this.otherStringLongMap = otherStringLongMap;
}
public Set<String> getStringSet2() {
return stringSet2;
}
public void setStringSet2(Set<String> stringSet2) {
this.stringSet2 = stringSet2;
}
public EnumSet<Colour> getEnumSet() {
return enumSet;
}
public void setEnumSet(EnumSet<Colour> enumSet) {
this.enumSet = enumSet;
}
public List<String> getStringList3() {
return stringList3;
}
public void setStringList3(List<String> stringList3) {
this.stringList3 = stringList3;
}
public Map<String, Long> getStringLongMapForNonGeneric() {
return stringLongMapForNonGeneric;
}
public void setStringLongMapForNonGeneric(Map<String, Long> stringLongMapForNonGeneric) {
this.stringLongMapForNonGeneric = stringLongMapForNonGeneric;
}
}

View File

@ -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 io.github.linpeilie.me.collection;
import org.springframework.stereotype.Component;
@Component
public class SourceTargetMapper {
protected StringHolder toStringHolder(String string) {
return new StringHolder( string );
}
protected String toString(StringHolder string) {
return string.getString();
}
}

View File

@ -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 io.github.linpeilie.me.collection;
/**
* @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 ) {
return other.string == null;
}
else {
return string.equals( other.string );
}
}
}

View File

@ -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 io.github.linpeilie.me.collection;
import java.util.ArrayList;
/**
* @author Stefan May
*/
public class StringHolderArrayList extends ArrayList<StringHolder> {
private static final long serialVersionUID = 1L;
}

View File

@ -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 io.github.linpeilie.me.collection;
import java.util.HashMap;
/**
* @author Stefan May
*/
public class StringHolderToLongMap extends HashMap<StringHolder, Long> {
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,197 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.github.linpeilie.me.collection;
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;
public class Target {
//CHECKSTYLE:OFF
public List<String> publicStringList;
//CHECKSTYLE:On
private List<String> stringList;
private List<String> otherStringList;
private ArrayList<String> stringArrayList;
private Set<String> stringSet;
private HashSet<String> stringHashSet;
private Collection<String> stringCollection;
private Collection<Integer> integerCollection;
private Set<String> anotherStringSet;
private Set<String> colours;
private Map<String, Long> stringLongMap;
private Map<String, Long> otherStringLongMap;
private List<String> stringListNoSetter;
private List<String> stringListNoSetter2;
@SuppressWarnings( "rawtypes" )
private Set set;
private EnumSet<Colour> enumSet;
private StringHolderArrayList nonGenericStringList;
private StringHolderToLongMap nonGenericMapStringtoLong;
public Target() {
otherStringLongMap = new HashMap<>();
otherStringLongMap.put( "not-present-after-mapping", 42L );
otherStringList = new ArrayList<>();
otherStringList.add( "not-present-after-mapping" );
}
public List<String> getStringList() {
return stringList;
}
public void setStringList(List<String> stringList) {
this.stringList = stringList;
}
public ArrayList<String> getStringArrayList() {
return stringArrayList;
}
public void setStringArrayList(ArrayList<String> stringArrayList) {
this.stringArrayList = stringArrayList;
}
public Set<String> getStringSet() {
return stringSet;
}
public void setStringSet(Set<String> stringSet) {
this.stringSet = stringSet;
}
public HashSet<String> getStringHashSet() {
return stringHashSet;
}
public void setStringHashSet(HashSet<String> stringHashSet) {
this.stringHashSet = stringHashSet;
}
public Collection<String> getStringCollection() {
return stringCollection;
}
public void setStringCollection(Collection<String> stringCollection) {
this.stringCollection = stringCollection;
}
public Collection<Integer> getIntegerCollection() {
return integerCollection;
}
public void setIntegerCollection(Collection<Integer> integerCollection) {
this.integerCollection = integerCollection;
}
@SuppressWarnings("rawtypes")
public Set getSet() {
return set;
}
@SuppressWarnings("rawtypes")
public void setSet(Set set) {
this.set = set;
}
public Set<String> getAnotherStringSet() {
return anotherStringSet;
}
public void setAnotherStringSet(Set<String> anotherStringSet) {
this.anotherStringSet = anotherStringSet;
}
public void setColours(Set<String> colours) {
this.colours = colours;
}
public Set<String> getColours() {
return colours;
}
public Map<String, Long> getStringLongMap() {
return stringLongMap;
}
public void setStringLongMap(Map<String, Long> stringLongMap) {
this.stringLongMap = stringLongMap;
}
public List<String> getStringListNoSetter() {
if ( stringListNoSetter == null ) {
stringListNoSetter = new ArrayList<>();
}
return stringListNoSetter;
}
public List<String> getStringListNoSetter2() {
if ( stringListNoSetter2 == null ) {
stringListNoSetter2 = new ArrayList<>();
}
return stringListNoSetter2;
}
public Map<String, Long> getOtherStringLongMap() {
return otherStringLongMap;
}
public void setOtherStringLongMap(Map<String, Long> otherStringLongMap) {
this.otherStringLongMap = otherStringLongMap;
}
public List<String> getOtherStringList() {
return otherStringList;
}
public void setOtherStringList(List<String> otherStringList) {
this.otherStringList = otherStringList;
}
public EnumSet<Colour> getEnumSet() {
return enumSet;
}
public void setEnumSet(EnumSet<Colour> enumSet) {
this.enumSet = enumSet;
}
public StringHolderArrayList getNonGenericStringList() {
return nonGenericStringList;
}
public void setNonGenericStringList(StringHolderArrayList nonGenericStringList) {
this.nonGenericStringList = nonGenericStringList;
}
public StringHolderToLongMap getNonGenericMapStringtoLong() {
return nonGenericMapStringtoLong;
}
public void setNonGenericMapStringtoLong(StringHolderToLongMap nonGenericMapStringtoLong) {
this.nonGenericMapStringtoLong = nonGenericMapStringtoLong;
}
}

View File

@ -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 io.github.linpeilie.me.collection;
import java.util.ArrayList;
import java.util.Collection;
/**
* @author Sjaak Derksen
*/
public class TestList<E> extends ArrayList<E> {
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<? extends E> c) {
addAllCalled = true;
return super.addAll( c );
}
}

View File

@ -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 io.github.linpeilie.me.collection;
import java.util.HashMap;
import java.util.Map;
/**
* @author Sjaak Derksen
*/
public class TestMap<K, V> extends HashMap<K, V> {
private static final long serialVersionUID = 1L;
private static boolean puttAllCalled = false;
public static boolean isPuttAllCalled() {
return puttAllCalled;
}
public static void setPuttAllCalled(boolean puttAllCalled) {
TestMap.puttAllCalled = puttAllCalled;
}
@Override
public void putAll(Map<? extends K, ? extends V> m) {
puttAllCalled = true;
super.putAll( m );
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder;
/**
* @author Sjaak Derksen
*/
public class CatException extends Exception {
private static final long serialVersionUID = 1L;
public CatException() {
}
public CatException(String msg) {
super( msg );
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder;
/**
* @author Sjaak Derksen
*/
public class DogException extends Exception {
private static final long serialVersionUID = 1L;
public DogException() {
}
public DogException(String msg) {
super( msg );
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder;
import com.google.common.collect.ImmutableMap;
import io.github.linpeilie.me.collection.adder._target.IndoorPet;
import io.github.linpeilie.me.collection.adder._target.OutdoorPet;
import io.github.linpeilie.me.collection.adder._target.Pet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.mapstruct.TargetType;
import org.springframework.stereotype.Component;
/**
* @author Sjaak Derksen
*/
@Component
public class PetMapper {
private static final Map<String, Long> PETS_TO_TARGET = ImmutableMap.<String, Long>builder()
.put( "rabbit", 1L )
.put( "mouse", 2L ).build();
private static final Map<Long, String> PETS_TO_SOURCE = ImmutableMap.<Long, String>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 CatException
* @throws DogException
*/
public Long toPet(String pet) throws CatException, DogException {
if ( "cat".equals( pet ) ) {
throw new CatException();
}
else if ( "dog".equals( pet ) ) {
throw new DogException();
}
return PETS_TO_TARGET.get( pet );
}
/**
* Method to be used when not using an adder
*
* @param pets
*
* @return
*
* @throws CatException
* @throws DogException
*/
public List<Long> toPets(List<String> pets) throws CatException, DogException {
List<Long> result = new ArrayList<>();
for ( String pet : pets ) {
result.add( toPet( pet ) );
}
return result;
}
@SuppressWarnings("unchecked")
public <T extends Pet> T toPet(String pet, @TargetType Class<T> clazz) throws CatException, DogException {
if ( clazz == IndoorPet.class ) {
return (T) new IndoorPet( toPet( pet ) );
}
if ( clazz == OutdoorPet.class ) {
return (T) new OutdoorPet( toPet( pet ) );
}
return null;
}
public List<String> toSourcePets(List<Long> pets) throws CatException, DogException {
List<String> result = new ArrayList<>();
for ( Long pet : pets ) {
result.add( PETS_TO_SOURCE.get( pet ) );
}
return result;
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.springframework.stereotype.Component;
/**
* @author Sjaak Derksen
*/
@Component
public class TeethMapper {
private static final Map<String, Integer> TEETH = ImmutableMap.<String, Integer>builder()
.put( "incisor", 1 )
.put( "canine", 2 )
.put( "moler", 3 ).build();
public Integer toTooth(String tooth) {
return TEETH.get( tooth );
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder._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;
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder._target;
/**
* @author Sjaak Derksen
*/
public class IndoorPet extends Pet {
private Long value;
public IndoorPet(Long value) {
this.value = value;
}
public Long getValue() {
return value;
}
public void setValue(Long value) {
this.value = value;
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder._target;
/**
* @author Sjaak Derksen
*/
public class OutdoorPet extends Pet {
private Long value;
public OutdoorPet(Long value) {
this.value = value;
}
public Long getValue() {
return value;
}
public void setValue(Long value) {
this.value = value;
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder._target;
/**
* @author Sjaak Derksen
*/
public class Pet {
}

View File

@ -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 io.github.linpeilie.me.collection.adder._target;
import java.util.ArrayList;
import java.util.List;
/**
* @author Sjaak Derksen
*/
public class Target {
private List<Long> pets;
public List<Long> getPets() {
return pets;
}
public void setPets(List<Long> pets) {
this.pets = pets;
}
public void addCat(Long cat) {
// dummy method to test selection mechanism
}
public void addDog(Long cat) {
// dummy method to test selection mechanism
}
public void addPets(Long cat) {
// dummy method to test selection mechanism
}
public Long addPet(Long pet) {
AdderUsageObserver.setUsed( true );
if ( pets == null ) {
pets = new ArrayList<>();
}
pets.add( pet );
return pet;
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder._target;
import io.github.linpeilie.me.collection.adder.source.Foo;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Sjaak Derksen
*/
public class Target2 {
private List<Foo> attributes = new ArrayList<Foo>();
public Foo addAttribute( Foo foo ) {
attributes.add( foo );
return foo;
}
public List<Foo> getAttributes() {
return attributes;
}
public void setAttributes( List<Foo> attributes ) {
this.attributes = attributes;
}
}

View File

@ -0,0 +1,38 @@
package io.github.linpeilie.me.collection.adder._target;
import java.util.ArrayList;
import java.util.List;
public class Target3 {
private List<Long> pets;
public List<Long> getPets() {
return pets;
}
public void setPets(List<Long> pets) {
this.pets = pets;
}
public void addCat(Long cat) {
// dummy method to test selection mechanism
}
public void addDog(Long cat) {
// dummy method to test selection mechanism
}
public void addPets(Long cat) {
// dummy method to test selection mechanism
}
public Long addPet(Long pet) {
AdderUsageObserver.setUsed( true );
if ( pets == null ) {
pets = new ArrayList<>();
}
pets.add( pet );
return pet;
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder._target;
import java.util.ArrayList;
import java.util.List;
/**
* @author Sjaak Derksen
*/
public class TargetDali {
private List<Integer> teeth;
public List<Integer> getTeeth() {
return teeth;
}
public void setTeeth(List<Integer> teeth) {
this.teeth = teeth;
}
public void addTeeth(Integer tooth) {
AdderUsageObserver.setUsed( true );
if ( teeth == null ) {
teeth = new ArrayList<>();
}
teeth.add( tooth );
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder._target;
import java.util.ArrayList;
import java.util.List;
/**
* @author Sjaak Derksen
*/
public class TargetHuman {
private List<Integer> teeth;
public List<Integer> getTeeth() {
return teeth;
}
public void setTeeth(List<Integer> teeth) {
this.teeth = teeth;
}
public void addTooth(Integer pet) {
AdderUsageObserver.setUsed( true );
if ( teeth == null ) {
teeth = new ArrayList<>();
}
teeth.add( pet );
}
public void addTeeth(Integer tooth) {
if ( teeth == null ) {
teeth = new ArrayList<>();
}
teeth.add( tooth );
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder._target;
import java.util.ArrayList;
import java.util.List;
/**
* @author Sjaak Derksen
*/
public class TargetOnlyGetter {
private List<Long> pets;
public List<Long> getPets() {
return pets;
}
public void addCat(Long cat) {
// dummy method to test selection mechanism
}
public void addDog(Long cat) {
// dummy method to test selection mechanism
}
public void addPets(Long cat) {
// dummy method to test selection mechanism
}
public void addPet(Long pet) {
AdderUsageObserver.setUsed( true );
if ( pets == null ) {
pets = new ArrayList<>();
}
pets.add( pet );
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder._target;
import java.util.ArrayList;
import java.util.List;
/**
* @author Sjaak Derksen
*/
public class TargetViaTargetType {
private List<IndoorPet> pets;
public List<IndoorPet> getPets() {
return pets;
}
public void setPets(List<IndoorPet> pets) {
this.pets = pets;
}
public void addPet(IndoorPet pet) {
AdderUsageObserver.setUsed( true );
if ( pets == null ) {
pets = new ArrayList<>();
}
pets.add( pet );
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder._target;
import java.util.ArrayList;
import java.util.List;
/**
* @author Filip Hrisafov
*/
public class TargetWithAnimals {
private List<String> animals = new ArrayList<>();
public List<String> getAnimals() {
return animals;
}
public void setAnimals(List<String> animals) {
this.animals = animals;
}
public void addAnimal(String animal) {
animals.add( animal );
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder._target;
import java.util.ArrayList;
import java.util.List;
/**
* @author Sjaak Derksen
*/
public class TargetWithoutSetter {
private List<Long> pets;
public List<Long> getPets() {
return pets;
}
public void addPet(Long pet) {
AdderUsageObserver.setUsed( true );
if ( pets == null ) {
pets = new ArrayList<>();
}
pets.add( pet );
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder.source;
/**
*
* @author Sjaak Derksen
*/
public class Foo {
}

View File

@ -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 io.github.linpeilie.me.collection.adder.source;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMapping;
import io.github.linpeilie.me.collection.adder.PetMapper;
import io.github.linpeilie.me.collection.adder.TeethMapper;
import io.github.linpeilie.me.collection.adder._target.Target;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapping;
/**
* @author Sjaak Derksen
*/
@AutoMapper(target = Target.class, reverseConvertGenerate = false, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, uses = {
PetMapper.class, TeethMapper.class})
public class SingleElementSource {
@AutoMapping(target = "pets")
private String pet;
public String getPet() {
return pet;
}
public void setPet(String pet) {
this.pet = pet;
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder.source;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMappers;
import io.github.linpeilie.me.collection.adder.PetMapper;
import io.github.linpeilie.me.collection.adder.TeethMapper;
import io.github.linpeilie.me.collection.adder._target.Target;
import io.github.linpeilie.me.collection.adder._target.TargetOnlyGetter;
import io.github.linpeilie.me.collection.adder._target.TargetViaTargetType;
import io.github.linpeilie.me.collection.adder._target.TargetWithoutSetter;
import java.util.List;
import org.mapstruct.CollectionMappingStrategy;
/**
* @author Sjaak Derksen
*/
@AutoMappers({
@AutoMapper(target = Target.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, uses = {
PetMapper.class, TeethMapper.class}),
@AutoMapper(target = TargetOnlyGetter.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, uses = {
PetMapper.class, TeethMapper.class}),
@AutoMapper(target = TargetViaTargetType.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, uses = {
PetMapper.class, TeethMapper.class}, reverseConvertGenerate = false),
@AutoMapper(target = TargetWithoutSetter.class,
collectionMappingStrategy = CollectionMappingStrategy.SETTER_PREFERRED,
uses = {PetMapper.class}
)
})
public class Source {
private List<String> pets;
public List<String> getPets() {
return pets;
}
public void setPets(List<String> pets) {
this.pets = pets;
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder.source;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.me.collection.adder._target.Target2;
import java.util.List;
import org.mapstruct.CollectionMappingStrategy;
/**
* @author Sjaak Derksen
*/
@AutoMapper(target = Target2.class,
reverseConvertGenerate = false,
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
public class Source2 {
private List<Foo> attributes;
public List<Foo> getAttributes() {
return attributes;
}
public void setAttributes(List<Foo> attributes) {
this.attributes = attributes;
}
}

View File

@ -0,0 +1,20 @@
package io.github.linpeilie.me.collection.adder.source;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.me.collection.adder.PetMapper;
import io.github.linpeilie.me.collection.adder._target.Target3;
import java.util.List;
@AutoMapper(target = Target3.class, uses = PetMapper.class)
public class Source3 {
private List<String> pets;
public List<String> getPets() {
return pets;
}
public void setPets(List<String> pets) {
this.pets = pets;
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder.source;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMappers;
import io.github.linpeilie.me.collection.adder.PetMapper;
import io.github.linpeilie.me.collection.adder.TeethMapper;
import io.github.linpeilie.me.collection.adder._target.TargetDali;
import io.github.linpeilie.me.collection.adder._target.TargetHuman;
import java.util.List;
import org.mapstruct.CollectionMappingStrategy;
/**
* @author Sjaak Derksen
*/
@AutoMappers({
@AutoMapper(target = TargetDali.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
uses = {PetMapper.class, TeethMapper.class}),
@AutoMapper(target = TargetHuman.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
uses = {PetMapper.class, TeethMapper.class})
})
public class SourceTeeth {
private List<String> teeth;
public List<String> getTeeth() {
return teeth;
}
public void setTeeth(List<String> teeth) {
this.teeth = teeth;
}
}

View File

@ -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 io.github.linpeilie.me.collection.adder.source;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMapping;
import io.github.linpeilie.me.collection.adder._target.TargetWithAnimals;
import java.util.List;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapping;
/**
* @author Filip Hrisafov
*/
@AutoMapper(target = TargetWithAnimals.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
public class SourceWithPets {
@AutoMapping(target = "animals")
private List<String> pets;
public List<String> getPets() {
return pets;
}
public void setPets(List<String> pets) {
this.pets = pets;
}
}

View File

@ -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 io.github.linpeilie.me.collection.defaultimplementation;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMappers;
import java.util.List;
import java.util.Map;
/**
* @author Andreas Gudian
*
*/
@AutoMappers({
@AutoMapper(target = NoSetterTarget.class)
})
public class NoSetterSource {
private List<String> listValues;
private Map<String, String> mapValues;
public List<String> getListValues() {
return listValues;
}
public void setListValues(List<String> listValues) {
this.listValues = listValues;
}
public Map<String, String> getMapValues() {
return mapValues;
}
public void setMapValues(Map<String, String> mapValues) {
this.mapValues = mapValues;
}
}

View File

@ -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 io.github.linpeilie.me.collection.defaultimplementation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Andreas Gudian
*
*/
public class NoSetterTarget {
private List<String> listValues = new ArrayList<String>();
private Map<String, String> mapValues = new HashMap<String, String>();
public List<String> getListValues() {
return listValues;
}
public Map<String, String> getMapValues() {
return mapValues;
}
}

View File

@ -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 io.github.linpeilie.me.collection.defaultimplementation;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMappers;
import io.github.linpeilie.annotations.AutoMapping;
import java.util.List;
import org.mapstruct.Mapping;
@AutoMappers({
@AutoMapper(target = Target.class)
})
public class Source {
@AutoMapping(target = "fooListNoSetter")
private List<SourceFoo> fooList;
public List<SourceFoo> getFooList() {
return fooList;
}
public void setFooList(List<SourceFoo> fooList) {
this.fooList = fooList;
}
}

View File

@ -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 io.github.linpeilie.me.collection.defaultimplementation;
import io.github.linpeilie.annotations.AutoMapper;
@AutoMapper(target = TargetFoo.class)
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;
}
}

View File

@ -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 io.github.linpeilie.me.collection.defaultimplementation;
import java.util.ArrayList;
import java.util.List;
public class Target {
private List<TargetFoo> fooListNoSetter;
public List<TargetFoo> getFooListNoSetter() {
if ( fooListNoSetter == null ) {
fooListNoSetter = new ArrayList<>();
}
return fooListNoSetter;
}
}

View File

@ -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 io.github.linpeilie.me.collection.defaultimplementation;
public class TargetFoo implements Comparable<TargetFoo> {
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 ) {
return other.name == null;
}
else {
return name.equals( other.name );
}
}
@Override
public int compareTo(TargetFoo o) {
return getName().compareTo( o.getName() );
}
}

View File

@ -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 io.github.linpeilie.me.collection.forged;
/**
*
* @author Sjaak Derksen
*/
public class Bar {
}

View File

@ -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 io.github.linpeilie.me.collection.forged;
/**
*
* @author Sjaak Derksen
*/
public class Foo {
}

View File

@ -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 io.github.linpeilie.me.collection.forged;
import io.github.linpeilie.annotations.AutoMapper;
import java.util.Map;
import java.util.Set;
@AutoMapper(target = Target.class)
public class Source {
//CHECKSTYLE:OFF
public Set<String> publicFooSet;
//CHECKSTYLE:ON
private Set<String> fooSet;
private Set<String> fooSet2;
//CHECKSTYLE:OFF
public Map<String, Long> publicBarMap;
//CHECKSTYLE:ON
private Map<String, Long> barMap;
private Map<String, Long> barMap2;
public Set<String> getFooSet() {
return fooSet;
}
public void setFooSet(Set<String> fooSet) {
this.fooSet = fooSet;
}
public Map<String, Long> getBarMap() {
return barMap;
}
public void setBarMap(Map<String, Long> barMap) {
this.barMap = barMap;
}
public Set<String> getFooSet2() {
return fooSet2;
}
public void setFooSet2( Set<String> fooSet2 ) {
this.fooSet2 = fooSet2;
}
public Map<String, Long> getBarMap2() {
return barMap2;
}
public void setBarMap2( Map<String, Long> barMap2 ) {
this.barMap2 = barMap2;
}
}

View File

@ -0,0 +1,54 @@
package io.github.linpeilie.me.collection.forged;
import io.github.linpeilie.annotations.AutoMapper;
import java.util.Map;
import java.util.Set;
import org.mapstruct.NullValueMappingStrategy;
@AutoMapper(target = Target1.class, nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public class Source1 {
//CHECKSTYLE:OFF
public Set<String> publicFooSet;
//CHECKSTYLE:ON
private Set<String> fooSet;
private Set<String> fooSet2;
//CHECKSTYLE:OFF
public Map<String, Long> publicBarMap;
//CHECKSTYLE:ON
private Map<String, Long> barMap;
private Map<String, Long> barMap2;
public Set<String> getFooSet() {
return fooSet;
}
public void setFooSet(Set<String> fooSet) {
this.fooSet = fooSet;
}
public Map<String, Long> getBarMap() {
return barMap;
}
public void setBarMap(Map<String, Long> barMap) {
this.barMap = barMap;
}
public Set<String> getFooSet2() {
return fooSet2;
}
public void setFooSet2( Set<String> fooSet2 ) {
this.fooSet2 = fooSet2;
}
public Map<String, Long> getBarMap2() {
return barMap2;
}
public void setBarMap2( Map<String, Long> barMap2 ) {
this.barMap2 = barMap2;
}
}

View File

@ -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 io.github.linpeilie.me.collection.forged;
import java.util.Map;
import java.util.Set;
public class Target {
private Set<Long> fooSet;
private Set<Long> fooSet2;
private Map<String, String> barMap;
private Map<String, String> barMap2;
private Set<Long> publicFooSet;
private Map<String, String> publicBarMap;
public Set<Long> getFooSet() {
return fooSet;
}
public void setFooSet(Set<Long> fooSet) {
this.fooSet = fooSet;
}
public Map<String, String> getBarMap() {
return barMap;
}
public void setBarMap(Map<String, String> barMap) {
this.barMap = barMap;
}
public Set<Long> getFooSet2() {
return fooSet2;
}
public void setFooSet2( Set<Long> fooSet2 ) {
this.fooSet2 = fooSet2;
}
public Map<String, String> getBarMap2() {
return barMap2;
}
public void setBarMap2( Map<String, String> barMap2 ) {
this.barMap2 = barMap2;
}
public Set<Long> getPublicFooSet() {
return publicFooSet;
}
public void setPublicFooSet(Set<Long> publicFooSet) {
this.publicFooSet = publicFooSet;
}
public Map<String, String> getPublicBarMap() {
return publicBarMap;
}
public void setPublicBarMap(Map<String, String> publicBarMap) {
this.publicBarMap = publicBarMap;
}
}

View File

@ -0,0 +1,66 @@
package io.github.linpeilie.me.collection.forged;
import io.github.linpeilie.annotations.AutoMapper;
import java.util.Map;
import java.util.Set;
import org.mapstruct.NullValueMappingStrategy;
@AutoMapper(target = Source1.class, nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public class Target1 {
private Set<Long> fooSet;
private Set<Long> fooSet2;
private Map<String, String> barMap;
private Map<String, String> barMap2;
private Set<Long> publicFooSet;
private Map<String, String> publicBarMap;
public Set<Long> getFooSet() {
return fooSet;
}
public void setFooSet(Set<Long> fooSet) {
this.fooSet = fooSet;
}
public Map<String, String> getBarMap() {
return barMap;
}
public void setBarMap(Map<String, String> barMap) {
this.barMap = barMap;
}
public Set<Long> getFooSet2() {
return fooSet2;
}
public void setFooSet2( Set<Long> fooSet2 ) {
this.fooSet2 = fooSet2;
}
public Map<String, String> getBarMap2() {
return barMap2;
}
public void setBarMap2( Map<String, String> barMap2 ) {
this.barMap2 = barMap2;
}
public Set<Long> getPublicFooSet() {
return publicFooSet;
}
public void setPublicFooSet(Set<Long> publicFooSet) {
this.publicFooSet = publicFooSet;
}
public Map<String, String> getPublicBarMap() {
return publicBarMap;
}
public void setPublicBarMap(Map<String, String> publicBarMap) {
this.publicBarMap = publicBarMap;
}
}

View File

@ -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 io.github.linpeilie.me.collection.immutabletarget;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMappers;
import java.util.List;
import org.mapstruct.CollectionMappingStrategy;
/**
* @author Sjaak Derksen
*/
@AutoMappers({
@AutoMapper(target = CupboardEntity.class, collectionMappingStrategy = CollectionMappingStrategy.TARGET_IMMUTABLE),
})
public class CupboardDto {
private List<String> content;
public List<String> getContent() {
return content;
}
public void setContent(List<String> content) {
this.content = content;
}
}

View File

@ -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 io.github.linpeilie.me.collection.immutabletarget;
import java.util.List;
/**
*
* @author Sjaak Derksen
*/
public class CupboardEntity {
private List<String> content;
public List<String> getContent() {
return content;
}
public void setContent(List<String> content) {
this.content = content;
}
}

View File

@ -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 io.github.linpeilie.me.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;
}
}

View File

@ -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 io.github.linpeilie.me.collection.iterabletononiterable;
import io.github.linpeilie.annotations.AutoMapper;
import java.util.List;
/**
*
* @author Saheb Preet Singh
*/
@AutoMapper(target = FruitsMenu.class)
public class FruitSalad {
private List<Fruit> fruits;
public FruitSalad(List<Fruit> fruits) {
this.fruits = fruits;
}
public List<Fruit> getFruits() {
return fruits;
}
public void setFruits(List<Fruit> fruits) {
this.fruits = fruits;
}
}

View File

@ -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 io.github.linpeilie.me.collection.iterabletononiterable;
import java.util.Iterator;
import java.util.List;
/**
*
* @author Saheb Preet Singh
*/
public class FruitsMenu implements Iterable<Fruit> {
private List<Fruit> fruits;
public FruitsMenu(List<Fruit> fruits) {
this.fruits = fruits;
}
public List<Fruit> getFruits() {
return fruits;
}
public void setFruits(List<Fruit> fruits) {
this.fruits = fruits;
}
@Override
public Iterator<Fruit> iterator() {
return this.fruits.iterator();
}
}

Some files were not shown because too many files have changed in this diff Show More