From e73dd1b485ecc535ae338492eb052d15758563cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20D=C3=BCsterhus?=
Date: Mon, 14 Dec 2020 11:44:04 +0100
Subject: [PATCH 001/471] Update chapter-2-set-up.asciidoc
See official maven doc on this: https://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html
Otherwise for example intellij doesn't recognize the compiler options on maven import
---
.../src/main/asciidoc/chapter-2-set-up.asciidoc | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc
index fb954ac58f..cb0067f2f3 100644
--- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc
+++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc
@@ -187,15 +187,15 @@ When invoking javac directly, these options are passed to the compiler in the fo
true
-
+
-Amapstruct.suppressGeneratorTimestamp=true
-
-
+
+
-Amapstruct.suppressGeneratorVersionInfoComment=true
-
-
+
+
-Amapstruct.verbose=true
-
+
From f84f756a4cc142c4cb4bdce540f009b79da03f23 Mon Sep 17 00:00:00 2001
From: Filip Hrisafov
Date: Sat, 5 Dec 2020 10:29:48 +0100
Subject: [PATCH 002/471] #2293 Use MapperConfig instead of MappingConfig in
the documentation
---
.../chapter-10-advanced-mapping-options.asciidoc | 12 ++++++------
.../chapter-5-data-type-conversions.asciidoc | 2 +-
.../ap/internal/model/source/DefaultOptions.java | 2 +-
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc
index ddf7fbcaed..4ccad69f2c 100644
--- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc
+++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc
@@ -161,13 +161,13 @@ The mechanism is also present on iterable mapping and map mapping. `@IterableMap
MapStruct offers control over the object to create when the source argument of the mapping method equals `null`. By default `null` will be returned.
-However, by specifying `nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT` on `@BeanMapping`, `@IterableMapping`, `@MapMapping`, or globally on `@Mapper` or `@MappingConfig`, the mapping result can be altered to return empty *default* values. This means for:
+However, by specifying `nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT` on `@BeanMapping`, `@IterableMapping`, `@MapMapping`, or globally on `@Mapper` or `@MapperConfig`, the mapping result can be altered to return empty *default* values. This means for:
* *Bean mappings*: an 'empty' target bean will be returned, with the exception of constants and expressions, they will be populated when present.
* *Iterables / Arrays*: an empty iterable will be returned.
* *Maps*: an empty map will be returned.
-The strategy works in a hierarchical fashion. Setting `nullValueMappingStrategy` on mapping method level will override `@Mapper#nullValueMappingStrategy`, and `@Mapper#nullValueMappingStrategy` will override `@MappingConfig#nullValueMappingStrategy`.
+The strategy works in a hierarchical fashion. Setting `nullValueMappingStrategy` on mapping method level will override `@Mapper#nullValueMappingStrategy`, and `@Mapper#nullValueMappingStrategy` will override `@MapperConfig#nullValueMappingStrategy`.
[[mapping-result-for-null-properties]]
@@ -179,13 +179,13 @@ By default the target property will be set to null.
However:
-1. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result can be altered to return *default* values.
+1. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MapperConfig`, the mapping result can be altered to return *default* values.
For `List` MapStruct generates an `ArrayList`, for `Map` a `HashMap`, for arrays an empty array, for `String` `""` and for primitive / boxed types a representation of `false` or `0`.
For all other objects an new instance is created. Please note that a default constructor is required. If not available, use the `@Mapping#defaultValue`.
-2. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result will be equal to the original value of the `@MappingTarget` annotated target.
+2. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MapperConfig`, the mapping result will be equal to the original value of the `@MappingTarget` annotated target.
-The strategy works in a hierarchical fashion. Setting `nullValuePropertyMappingStrategy` on mapping method level will override `@Mapper#nullValuePropertyMappingStrategy`, and `@Mapper#nullValuePropertyMappingStrategy` will override `@MappingConfig#nullValuePropertyMappingStrategy`.
+The strategy works in a hierarchical fashion. Setting `nullValuePropertyMappingStrategy` on mapping method level will override `@Mapper#nullValuePropertyMappingStrategy`, and `@Mapper#nullValuePropertyMappingStrategy` will override `@MapperConfig#nullValuePropertyMappingStrategy`.
[NOTE]
====
@@ -213,7 +213,7 @@ First calling a mapping method on the source property is not protected by a null
The option `nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS` will always include a null check when source is non primitive, unless a source presence checker is defined on the source bean.
-The strategy works in a hierarchical fashion. `@Mapping#nullValueCheckStrategy` will override `@BeanMapping#nullValueCheckStrategy`, `@BeanMapping#nullValueCheckStrategy` will override `@Mapper#nullValueCheckStrategy` and `@Mapper#nullValueCheckStrategy` will override `@MappingConfig#nullValueCheckStrategy`.
+The strategy works in a hierarchical fashion. `@Mapping#nullValueCheckStrategy` will override `@BeanMapping#nullValueCheckStrategy`, `@BeanMapping#nullValueCheckStrategy` will override `@Mapper#nullValueCheckStrategy` and `@Mapper#nullValueCheckStrategy` will override `@MaperConfig#nullValueCheckStrategy`.
[[source-presence-check]]
=== Source presence checking
diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc
index 725c69bad0..9619d0fe26 100644
--- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc
+++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc
@@ -155,7 +155,7 @@ When generating the implementation of a mapping method, MapStruct will apply the
. If no such method was found MapStruct will try to generate an automatic sub-mapping method that will do the mapping between the source and target attributes.
. If MapStruct could not create a name based mapping method an error will be raised at build time, indicating the non-mappable attribute and its path.
-A mapping control (`MappingControl`) can be defined on all levels (`@MappingConfig`, `@Mapper`, `@BeanMapping`, `@Mapping`), the latter taking precedence over the former. For example: `@Mapper( mappingControl = NoComplexMapping.class )` takes precedence over `@MapperConfig( mappingControl = DeepClone.class )`. `@IterableMapping` and `@MapMapping` work similar as `@Mapping`. MappingControl is experimental from MapStruct 1.4.
+A mapping control (`MappingControl`) can be defined on all levels (`@MapperConfig`, `@Mapper`, `@BeanMapping`, `@Mapping`), the latter taking precedence over the former. For example: `@Mapper( mappingControl = NoComplexMapping.class )` takes precedence over `@MapperConfig( mappingControl = DeepClone.class )`. `@IterableMapping` and `@MapMapping` work similar as `@Mapping`. MappingControl is experimental from MapStruct 1.4.
`MappingControl` has an enum that corresponds to the first 4 options above: `MappingControl.Use#DIRECT`, `MappingControl.Use#MAPPING_METHOD`, `MappingControl.Use#BUILT_IN_CONVERSION` and `MappingControl.Use#COMPLEX_MAPPING` the presence of which allows the user to switch *on* a option. The absence of an enum switches *off* a mapping option. Default they are all present enabling all mapping options.
[NOTE]
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java
index 4d80bf57be..58f03ad55d 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java
@@ -119,7 +119,7 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() {
public BuilderGem getBuilder() {
// TODO: I realized this is not correct, however it needs to be null in order to keep downward compatibility
// but assuming a default @Builder will make testcases fail. Not having a default means that you need to
- // specify this mandatory on @MappingConfig and @Mapper.
+ // specify this mandatory on @MapperConfig and @Mapper.
return null;
}
From 700293f0898fb5e9014d0e241bc9674695430ebe Mon Sep 17 00:00:00 2001
From: Filip Hrisafov
Date: Sat, 19 Dec 2020 19:50:32 +0100
Subject: [PATCH 003/471] #2301 Implicitly ignore forward inherited mappings
from different method types
---
.../ap/internal/model/BeanMappingMethod.java | 9 +++
.../ap/test/bugs/_2301/Artifact.java | 66 +++++++++++++++++++
.../ap/test/bugs/_2301/ArtifactDto.java | 22 +++++++
.../ap/test/bugs/_2301/Issue2301Mapper.java | 28 ++++++++
.../ap/test/bugs/_2301/Issue2301Test.java | 40 +++++++++++
5 files changed, 165 insertions(+)
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Artifact.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/ArtifactDto.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Mapper.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Test.java
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java
index 7ea17bf27b..459a4f82d9 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java
@@ -938,6 +938,15 @@ private boolean handleDefinedMapping(MappingReference mappingRef, Type resultTyp
if ( targetWriteAccessor == null ) {
if ( targetReadAccessor == null ) {
+ if ( mapping.getInheritContext() != null && mapping.getInheritContext().isForwarded() &&
+ mapping.getInheritContext().getTemplateMethod().isUpdateMethod() != method.isUpdateMethod() ) {
+ // When a configuration is inherited and the template method is not same type as the current
+ // method then we can safely ignore this mapping.
+ // This means that a property which is inherited might be present for a direct mapping
+ // via the Builder, but not for an update mapping (directly on the object itself),
+ // or vice versa
+ return false;
+ }
Set readAccessors = resultTypeToMap.getPropertyReadAccessors().keySet();
String mostSimilarProperty = Strings.getMostSimilarWord( targetPropertyName, readAccessors );
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Artifact.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Artifact.java
new file mode 100644
index 0000000000..316959f48b
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Artifact.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2301;
+
+import java.util.Set;
+
+/**
+ * @author Filip Hrisafov
+ */
+public class Artifact {
+
+ private String name;
+ private Set dependantBuildRecords;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set getDependantBuildRecords() {
+ return dependantBuildRecords;
+ }
+
+ public void setDependantBuildRecords(Set dependantBuildRecords) {
+ this.dependantBuildRecords = dependantBuildRecords;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+
+ private String name;
+ private Set dependantBuildRecords;
+
+ public Artifact build() {
+ Artifact artifact = new Artifact();
+ artifact.setName( name );
+ artifact.setDependantBuildRecords( dependantBuildRecords );
+
+ return artifact;
+ }
+
+ public Builder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public Builder dependantBuildRecord(String dependantBuildRecord) {
+ this.dependantBuildRecords.add( dependantBuildRecord );
+ return this;
+ }
+
+ public Builder dependantBuildRecords(Set dependantBuildRecords) {
+ this.dependantBuildRecords = dependantBuildRecords;
+ return this;
+ }
+ }
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/ArtifactDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/ArtifactDto.java
new file mode 100644
index 0000000000..68b9280930
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/ArtifactDto.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2301;
+
+/**
+ * @author Filip Hrisafov
+ */
+public class ArtifactDto {
+
+ private final String name;
+
+ public ArtifactDto(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Mapper.java
new file mode 100644
index 0000000000..cd3cca3744
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Mapper.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2301;
+
+import org.mapstruct.InheritConfiguration;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.MappingTarget;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * @author Filip Hrisafov
+ */
+@Mapper
+public interface Issue2301Mapper {
+
+ Issue2301Mapper INSTANCE = Mappers.getMapper( Issue2301Mapper.class );
+
+ @Mapping(target = "dependantBuildRecords", ignore = true)
+ @Mapping(target = "dependantBuildRecord", ignore = true)
+ Artifact map(ArtifactDto dto);
+
+ @InheritConfiguration
+ void update(@MappingTarget Artifact artifact, ArtifactDto dto);
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Test.java
new file mode 100644
index 0000000000..8c237a2d30
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Test.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2301;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mapstruct.ap.testutil.IssueKey;
+import org.mapstruct.ap.testutil.WithClasses;
+import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * @author Filip Hrisafov
+ */
+@IssueKey("2301")
+@RunWith(AnnotationProcessorTestRunner.class)
+@WithClasses({
+ Artifact.class,
+ ArtifactDto.class,
+ Issue2301Mapper.class
+})
+public class Issue2301Test {
+
+ @Test
+ public void shouldCorrectlyIgnoreProperties() {
+ Artifact artifact = Issue2301Mapper.INSTANCE.map( new ArtifactDto( "mapstruct" ) );
+
+ assertThat( artifact ).isNotNull();
+ assertThat( artifact.getName() ).isEqualTo( "mapstruct" );
+ assertThat( artifact.getDependantBuildRecords() ).isNull();
+
+ Issue2301Mapper.INSTANCE.update( artifact, new ArtifactDto( "mapstruct-processor" ) );
+
+ assertThat( artifact.getName() ).isEqualTo( "mapstruct-processor" );
+ }
+}
From 4223e3ab812a496aeb31b67a63737fb648bd2ddb Mon Sep 17 00:00:00 2001
From: Tomas Poledny
Date: Thu, 5 Nov 2020 14:09:30 +0100
Subject: [PATCH 004/471] #2255 Add constants for componentModel
---
core/src/main/java/org/mapstruct/Mapper.java | 6 +--
.../main/java/org/mapstruct/MapperConfig.java | 2 +-
.../java/org/mapstruct/MappingConstants.java | 45 +++++++++++++++++++
.../chapter-4-retrieving-a-mapper.asciidoc | 6 +--
.../chapter-5-data-type-conversions.asciidoc | 2 +-
.../cdi/DecoratedSourceTargetMapper.java | 3 +-
.../itest/cdi/SourceTargetMapper.java | 3 +-
.../jsr330/DecoratedSourceTargetMapper.java | 3 +-
.../SecondDecoratedSourceTargetMapper.java | 3 +-
.../itest/jsr330/SourceTargetMapper.java | 3 +-
.../spring/DecoratedSourceTargetMapper.java | 3 +-
.../SecondDecoratedSourceTargetMapper.java | 3 +-
.../itest/spring/SourceTargetMapper.java | 3 +-
.../ap/internal/gem/MappingConstantsGem.java | 19 ++++++++
.../processor/CdiComponentProcessor.java | 3 +-
.../processor/Jsr330ComponentProcessor.java | 3 +-
.../processor/MapperServiceProcessor.java | 3 +-
.../processor/SpringComponentProcessor.java | 3 +-
.../ap/test/bugs/_1395/Issue1395Mapper.java | 4 +-
.../ap/test/bugs/_880/Issue880Test.java | 5 ++-
.../_880/UsesConfigFromAnnotationMapper.java | 3 +-
.../test/decorator/jsr330/PersonMapper.java | 3 +-
.../spring/constructor/PersonMapper.java | 3 +-
.../decorator/spring/field/PersonMapper.java | 3 +-
.../DestinationClassNameWithJsr330Mapper.java | 3 +-
.../mapstruct/ap/test/gem/ConstantTest.java | 9 ++++
.../ap/test/imports/SourceTargetMapper.java | 3 +-
...Jsr330DefaultCompileOptionFieldMapper.java | 4 +-
...Jsr330DefaultCompileOptionFieldMapper.java | 3 +-
...rJsr330CompileOptionConstructorMapper.java | 3 +-
...rJsr330CompileOptionConstructorMapper.java | 3 +-
.../constructor/ConstructorJsr330Config.java | 4 +-
.../CustomerJsr330ConstructorMapper.java | 3 +-
.../field/CustomerJsr330FieldMapper.java | 4 +-
.../jsr330/field/FieldJsr330Config.java | 3 +-
.../_default/CustomerSpringDefaultMapper.java | 3 +-
.../_default/GenderSpringDefaultMapper.java | 3 +-
...dSpringCompileOptionConstructorMapper.java | 3 +-
...rSpringCompileOptionConstructorMapper.java | 3 +-
...rSpringCompileOptionConstructorMapper.java | 3 +-
.../constructor/ConstructorSpringConfig.java | 4 +-
...CustomerRecordSpringConstructorMapper.java | 3 +-
.../CustomerSpringConstructorMapper.java | 3 +-
.../field/CustomerSpringFieldMapper.java | 4 +-
.../spring/field/FieldSpringConfig.java | 3 +-
.../samename/Jsr330SourceTargetMapper.java | 3 +-
46 files changed, 166 insertions(+), 48 deletions(-)
diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java
index 233907621a..5ed9eab17f 100644
--- a/core/src/main/java/org/mapstruct/Mapper.java
+++ b/core/src/main/java/org/mapstruct/Mapper.java
@@ -35,7 +35,7 @@
*
*
* // we have MarkMapper (map field "mark" to field "name" to upper case)
- * @Mapper(componentModel = "spring")
+ * @Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
* public class MarkMapper {
* public String mapMark(String mark) {
* return mark.toUpperCase();
@@ -43,7 +43,7 @@
* }
* // we have CarMapper
* @Mapper(
- * componentModel = "spring",
+ * componentModel = MappingConstants.ComponentModel.SPRING,
* uses = MarkMapper.class,
* injectionStrategy = InjectionStrategy.CONSTRUCTOR)
* public interface CarMapper {
@@ -148,7 +148,7 @@
*
* @return The component model for the generated mapper.
*/
- String componentModel() default "default";
+ String componentModel() default MappingConstants.ComponentModel.DEFAULT;
/**
* Specifies the name of the implementation class. The {@code } will be replaced by the
diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java
index d251ff3798..ecfd888ca2 100644
--- a/core/src/main/java/org/mapstruct/MapperConfig.java
+++ b/core/src/main/java/org/mapstruct/MapperConfig.java
@@ -135,7 +135,7 @@
*
* @return The component model for the generated mapper.
*/
- String componentModel() default "default";
+ String componentModel() default MappingConstants.ComponentModel.DEFAULT;
/**
* Specifies the name of the implementation class. The {@code } will be replaced by the
diff --git a/core/src/main/java/org/mapstruct/MappingConstants.java b/core/src/main/java/org/mapstruct/MappingConstants.java
index 2c5757038f..6e30f08c21 100644
--- a/core/src/main/java/org/mapstruct/MappingConstants.java
+++ b/core/src/main/java/org/mapstruct/MappingConstants.java
@@ -66,4 +66,49 @@ private MappingConstants() {
*/
public static final String STRIP_PREFIX_TRANSFORMATION = "stripPrefix";
+ /**
+ * Specifies the component model constants to which the generated mapper should adhere.
+ * It can be used with the annotation {@link Mapper#componentModel()} or {@link MapperConfig#componentModel()}
+ *
+ *
+ * Example:
+ *
+ *
+ * // Spring component model
+ * @Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
+ *
+ *
+ * @since 1.5.0
+ */
+ public static final class ComponentModel {
+
+ private ComponentModel() {
+ }
+
+ /**
+ * The mapper uses no component model, instances are typically retrieved
+ * via {@link org.mapstruct.factory.Mappers#getMapper(java.lang.Class)}
+ *
+ */
+ public static final String DEFAULT = "default";
+
+ /**
+ * The generated mapper is an application-scoped CDI bean and can be retrieved via @Inject
+ */
+ public static final String CDI = "cdi";
+
+ /**
+ * The generated mapper is a Spring bean and can be retrieved via @Autowired
+ *
+ */
+ public static final String SPRING = "spring";
+
+ /**
+ * The generated mapper is annotated with @javax.inject.Named and @Singleton, and can be retrieved via @Inject
+ *
+ */
+ public static final String JSR330 = "jsr330";
+
+ }
+
}
diff --git a/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc
index 75b5b10294..724b42fbb7 100644
--- a/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc
+++ b/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc
@@ -69,14 +69,14 @@ Note that mappers generated by MapStruct are stateless and thread-safe and thus
If you're working with a dependency injection framework such as http://jcp.org/en/jsr/detail?id=346[CDI] (Contexts and Dependency Injection for Java^TM^ EE) or the http://www.springsource.org/spring-framework[Spring Framework], it is recommended to obtain mapper objects via dependency injection and *not* via the `Mappers` class as described above. For that purpose you can specify the component model which generated mapper classes should be based on either via `@Mapper#componentModel` or using a processor option as described in <>.
-Currently there is support for CDI and Spring (the latter either via its custom annotations or using the JSR 330 annotations). See <> for the allowed values of the `componentModel` attribute which are the same as for the `mapstruct.defaultComponentModel` processor option. In both cases the required annotations will be added to the generated mapper implementations classes in order to make the same subject to dependency injection. The following shows an example using CDI:
+Currently there is support for CDI and Spring (the latter either via its custom annotations or using the JSR 330 annotations). See <> for the allowed values of the `componentModel` attribute which are the same as for the `mapstruct.defaultComponentModel` processor option and constants are defined in a class `MappingConstants.ComponentModel`. In both cases the required annotations will be added to the generated mapper implementations classes in order to make the same subject to dependency injection. The following shows an example using CDI:
.A mapper using the CDI component model
====
[source, java, linenums]
[subs="verbatim,attributes"]
----
-@Mapper(componentModel = "cdi")
+@Mapper(componentModel = MappingConstants.ComponentModel.CDI)
public interface CarMapper {
CarDto carToCarDto(Car car);
@@ -110,7 +110,7 @@ This can be done by either providing the injection strategy via `@Mapper` or `@M
[source, java, linenums]
[subs="verbatim,attributes"]
----
-@Mapper(componentModel = "cdi", uses = EngineMapper.class, injectionStrategy = InjectionStrategy.CONSTRUCTOR)
+@Mapper(componentModel = MappingConstants.ComponentModel.CDI, uses = EngineMapper.class, injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface CarMapper {
CarDto carToCarDto(Car car);
}
diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc
index 9619d0fe26..9978cd3f25 100644
--- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc
+++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc
@@ -405,7 +405,7 @@ public class ReferenceMapper {
}
}
-@Mapper(componentModel = "cdi", uses = ReferenceMapper.class )
+@Mapper(componentModel = MappingConstants.ComponentModel.CDI, uses = ReferenceMapper.class )
public interface CarMapper {
Car carDtoToCar(CarDto carDto);
diff --git a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/DecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/DecoratedSourceTargetMapper.java
index 1787fd3c90..18a57ce25e 100644
--- a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/DecoratedSourceTargetMapper.java
+++ b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/DecoratedSourceTargetMapper.java
@@ -6,10 +6,11 @@
package org.mapstruct.itest.cdi;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.DecoratedWith;
import org.mapstruct.itest.cdi.other.DateMapper;
-@Mapper( componentModel = "cdi", uses = DateMapper.class )
+@Mapper( componentModel = MappingConstants.ComponentModel.CDI, uses = DateMapper.class )
public interface DecoratedSourceTargetMapper {
Target sourceToTarget(Source source);
diff --git a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapper.java b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapper.java
index 3a46a20889..eb895f5e5a 100644
--- a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapper.java
+++ b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapper.java
@@ -6,9 +6,10 @@
package org.mapstruct.itest.cdi;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.itest.cdi.other.DateMapper;
-@Mapper(componentModel = "cdi", uses = DateMapper.class)
+@Mapper(componentModel = MappingConstants.ComponentModel.CDI, uses = DateMapper.class)
public interface SourceTargetMapper {
Target sourceToTarget(Source source);
diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/DecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/DecoratedSourceTargetMapper.java
index 137f234c26..77f5ec558a 100644
--- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/DecoratedSourceTargetMapper.java
+++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/DecoratedSourceTargetMapper.java
@@ -6,10 +6,11 @@
package org.mapstruct.itest.jsr330;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.DecoratedWith;
import org.mapstruct.itest.jsr330.other.DateMapper;
-@Mapper(componentModel = "jsr330", uses = DateMapper.class)
+@Mapper(componentModel = MappingConstants.ComponentModel.JSR330, uses = DateMapper.class)
@DecoratedWith(SourceTargetMapperDecorator.class)
public interface DecoratedSourceTargetMapper {
diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondDecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondDecoratedSourceTargetMapper.java
index cdec6dc19d..f088e21de4 100644
--- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondDecoratedSourceTargetMapper.java
+++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondDecoratedSourceTargetMapper.java
@@ -6,10 +6,11 @@
package org.mapstruct.itest.jsr330;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.DecoratedWith;
import org.mapstruct.itest.jsr330.other.DateMapper;
-@Mapper(componentModel = "jsr330", uses = DateMapper.class)
+@Mapper(componentModel = MappingConstants.ComponentModel.JSR330, uses = DateMapper.class)
@DecoratedWith(SecondSourceTargetMapperDecorator.class)
public interface SecondDecoratedSourceTargetMapper {
diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapper.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapper.java
index c5ba3670fb..a96a860da5 100644
--- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapper.java
+++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapper.java
@@ -6,9 +6,10 @@
package org.mapstruct.itest.jsr330;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.itest.jsr330.other.DateMapper;
-@Mapper(componentModel = "jsr330", uses = DateMapper.class)
+@Mapper(componentModel = MappingConstants.ComponentModel.JSR330, uses = DateMapper.class)
public interface SourceTargetMapper {
Target sourceToTarget(Source source);
diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/DecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/DecoratedSourceTargetMapper.java
index f1bbf87d3a..a020ab2b27 100644
--- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/DecoratedSourceTargetMapper.java
+++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/DecoratedSourceTargetMapper.java
@@ -6,10 +6,11 @@
package org.mapstruct.itest.spring;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.DecoratedWith;
import org.mapstruct.itest.spring.other.DateMapper;
-@Mapper( componentModel = "spring", uses = DateMapper.class )
+@Mapper( componentModel = MappingConstants.ComponentModel.SPRING, uses = DateMapper.class )
@DecoratedWith( SourceTargetMapperDecorator.class )
public interface DecoratedSourceTargetMapper {
diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondDecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondDecoratedSourceTargetMapper.java
index 88e2906300..7c04262595 100644
--- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondDecoratedSourceTargetMapper.java
+++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondDecoratedSourceTargetMapper.java
@@ -6,10 +6,11 @@
package org.mapstruct.itest.spring;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.DecoratedWith;
import org.mapstruct.itest.spring.other.DateMapper;
-@Mapper( componentModel = "spring", uses = DateMapper.class )
+@Mapper( componentModel = MappingConstants.ComponentModel.SPRING, uses = DateMapper.class )
@DecoratedWith( SecondSourceTargetMapperDecorator.class )
public interface SecondDecoratedSourceTargetMapper {
diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapper.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapper.java
index 06e4be4d22..e6d6b46339 100644
--- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapper.java
+++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapper.java
@@ -6,9 +6,10 @@
package org.mapstruct.itest.spring;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.itest.spring.other.DateMapper;
-@Mapper(componentModel = "spring", uses = DateMapper.class)
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = DateMapper.class)
public interface SourceTargetMapper {
Target sourceToTarget(Source source);
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java
index 685f5a543c..5df7fd3f92 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java
@@ -28,4 +28,23 @@ private MappingConstantsGem() {
public static final String PREFIX_TRANSFORMATION = "prefix";
public static final String STRIP_PREFIX_TRANSFORMATION = "stripPrefix";
+
+ /**
+ * Gem for the class {@link org.mapstruct.MappingConstants.ComponentModel}
+ *
+ */
+ public final class ComponentModelGem {
+
+ private ComponentModelGem() {
+ }
+
+ public static final String DEFAULT = "default";
+
+ public static final String CDI = "cdi";
+
+ public static final String SPRING = "spring";
+
+ public static final String JSR330 = "jsr330";
+ }
+
}
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java
index a5e3458681..74ff2b118b 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java
@@ -9,6 +9,7 @@
import java.util.Collections;
import java.util.List;
+import org.mapstruct.ap.internal.gem.MappingConstantsGem;
import org.mapstruct.ap.internal.model.Annotation;
import org.mapstruct.ap.internal.model.Mapper;
@@ -23,7 +24,7 @@ public class CdiComponentProcessor extends AnnotationBasedComponentModelProcesso
@Override
protected String getComponentModelIdentifier() {
- return "cdi";
+ return MappingConstantsGem.ComponentModelGem.CDI;
}
@Override
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java
index 4f7b46d643..18a6e4f69d 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java
@@ -9,6 +9,7 @@
import java.util.Collections;
import java.util.List;
+import org.mapstruct.ap.internal.gem.MappingConstantsGem;
import org.mapstruct.ap.internal.model.Annotation;
import org.mapstruct.ap.internal.model.Mapper;
@@ -23,7 +24,7 @@
public class Jsr330ComponentProcessor extends AnnotationBasedComponentModelProcessor {
@Override
protected String getComponentModelIdentifier() {
- return "jsr330";
+ return MappingConstantsGem.ComponentModelGem.JSR330;
}
@Override
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java
index f74a84c491..c9e37596f7 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java
@@ -11,6 +11,7 @@
import javax.tools.FileObject;
import javax.tools.StandardLocation;
+import org.mapstruct.ap.internal.gem.MappingConstantsGem;
import org.mapstruct.ap.internal.model.GeneratedType;
import org.mapstruct.ap.internal.model.Mapper;
import org.mapstruct.ap.internal.model.ServicesEntry;
@@ -38,7 +39,7 @@ public Void process(ProcessorContext context, TypeElement mapperTypeElement, Map
String componentModel =
MapperOptions.getInstanceOn( mapperTypeElement, context.getOptions() ).componentModel( );
- spiGenerationNeeded = "default".equals( componentModel );
+ spiGenerationNeeded = MappingConstantsGem.ComponentModelGem.DEFAULT.equals( componentModel );
}
if ( !context.isErroneous() && spiGenerationNeeded && mapper.hasCustomImplementation() ) {
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java
index 7780501a78..f7aa9b4fea 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java
@@ -10,6 +10,7 @@
import java.util.Collections;
import java.util.List;
+import org.mapstruct.ap.internal.gem.MappingConstantsGem;
import org.mapstruct.ap.internal.model.Annotation;
import org.mapstruct.ap.internal.model.Mapper;
@@ -24,7 +25,7 @@
public class SpringComponentProcessor extends AnnotationBasedComponentModelProcessor {
@Override
protected String getComponentModelIdentifier() {
- return "spring";
+ return MappingConstantsGem.ComponentModelGem.SPRING;
}
@Override
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java
index 559e39512e..ebc9ae27e0 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java
@@ -7,11 +7,13 @@
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
/**
* @author Filip Hrisafov
*/
-@Mapper(injectionStrategy = InjectionStrategy.CONSTRUCTOR, componentModel = "spring", uses = NotUsedService.class)
+@Mapper(injectionStrategy = InjectionStrategy.CONSTRUCTOR, componentModel = MappingConstants.ComponentModel.SPRING,
+ uses = NotUsedService.class)
public interface Issue1395Mapper {
Target map(Source source);
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java
index 2a80961bc5..4d491b1b2c 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java
@@ -10,6 +10,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
@@ -30,7 +31,7 @@
Poodle.class,
Config.class })
@ProcessorOptions({
- @ProcessorOption(name = "mapstruct.defaultComponentModel", value = "spring"),
+ @ProcessorOption(name = "mapstruct.defaultComponentModel", value = MappingConstants.ComponentModel.SPRING),
@ProcessorOption(name = "mapstruct.unmappedTargetPolicy", value = "ignore") })
public class Issue880Test {
@Rule
@@ -40,7 +41,7 @@ public class Issue880Test {
@ExpectedCompilationOutcome(
value = CompilationResult.SUCCEEDED,
diagnostics = @Diagnostic(kind = Kind.WARNING,
- type = UsesConfigFromAnnotationMapper.class, line = 16,
+ type = UsesConfigFromAnnotationMapper.class, line = 17,
message = "Unmapped target property: \"core\"."))
public void compilationSucceedsAndAppliesCorrectComponentModel() {
generatedSource.forMapper( UsesConfigFromAnnotationMapper.class ).containsNoImportFor( Component.class );
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java
index ed4267cf12..d9a1efe33e 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java
@@ -6,12 +6,13 @@
package org.mapstruct.ap.test.bugs._880;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
/**
* @author Andreas Gudian
*
*/
-@Mapper(componentModel = "default", config = Config.class)
+@Mapper(componentModel = MappingConstants.ComponentModel.DEFAULT, config = Config.class)
public interface UsesConfigFromAnnotationMapper {
Poodle metamorph(Object essence);
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapper.java
index b37557bae1..770393f817 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapper.java
@@ -8,12 +8,13 @@
import org.mapstruct.DecoratedWith;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.decorator.Address;
import org.mapstruct.ap.test.decorator.AddressDto;
import org.mapstruct.ap.test.decorator.Person;
import org.mapstruct.ap.test.decorator.PersonDto;
-@Mapper(componentModel = "jsr330")
+@Mapper(componentModel = MappingConstants.ComponentModel.JSR330)
@DecoratedWith(PersonMapperDecorator.class)
public interface PersonMapper {
diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java
index e1e57eb6f3..4ada1124c0 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java
@@ -9,12 +9,13 @@
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.decorator.Address;
import org.mapstruct.ap.test.decorator.AddressDto;
import org.mapstruct.ap.test.decorator.Person;
import org.mapstruct.ap.test.decorator.PersonDto;
-@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR)
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, injectionStrategy = InjectionStrategy.CONSTRUCTOR)
@DecoratedWith(PersonMapperDecorator.class)
public interface PersonMapper {
diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java
index fc03b6ce1a..5cbe867e7a 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java
@@ -9,12 +9,13 @@
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.decorator.Address;
import org.mapstruct.ap.test.decorator.AddressDto;
import org.mapstruct.ap.test.decorator.Person;
import org.mapstruct.ap.test.decorator.PersonDto;
-@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.FIELD)
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, injectionStrategy = InjectionStrategy.FIELD)
@DecoratedWith(PersonMapperDecorator.class)
public interface PersonMapper {
diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java
index 48d5547ff2..92c72a877d 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java
@@ -6,11 +6,12 @@
package org.mapstruct.ap.test.destination;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
/**
* @author Christophe Labouisse on 27/05/2015.
*/
-@Mapper(implementationName = "Jsr330Impl", componentModel = "jsr330")
+@Mapper(implementationName = "Jsr330Impl", componentModel = MappingConstants.ComponentModel.JSR330)
public interface DestinationClassNameWithJsr330Mapper {
String intToString(Integer source);
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java
index a2a6afefde..69fa56a310 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java
@@ -30,4 +30,13 @@ public void constantsShouldBeEqual() {
assertThat( MappingConstants.STRIP_PREFIX_TRANSFORMATION )
.isEqualTo( MappingConstantsGem.STRIP_PREFIX_TRANSFORMATION );
}
+
+ @Test
+ public void componentModelContantsShouldBeEqual() {
+ assertThat( MappingConstants.ComponentModel.DEFAULT )
+ .isEqualTo( MappingConstantsGem.ComponentModelGem.DEFAULT );
+ assertThat( MappingConstants.ComponentModel.CDI ).isEqualTo( MappingConstantsGem.ComponentModelGem.CDI );
+ assertThat( MappingConstants.ComponentModel.SPRING ).isEqualTo( MappingConstantsGem.ComponentModelGem.SPRING );
+ assertThat( MappingConstants.ComponentModel.JSR330 ).isEqualTo( MappingConstantsGem.ComponentModelGem.JSR330 );
+ }
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java
index 8e5e7b0de2..1380ca400a 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java
@@ -8,6 +8,7 @@
import java.util.Date;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.imports.referenced.Source;
import org.mapstruct.ap.test.imports.referenced.Target;
import org.mapstruct.ap.test.imports.to.Foo;
@@ -16,7 +17,7 @@
/**
* @author Gunnar Morling
*/
-@Mapper(componentModel = "jsr330")
+@Mapper(componentModel = MappingConstants.ComponentModel.JSR330)
public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/CustomerJsr330DefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/CustomerJsr330DefaultCompileOptionFieldMapper.java
index 9ce6b1215e..7fcbe97d5a 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/CustomerJsr330DefaultCompileOptionFieldMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/CustomerJsr330DefaultCompileOptionFieldMapper.java
@@ -6,13 +6,15 @@
package org.mapstruct.ap.test.injectionstrategy.jsr330._default;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/**
* @author Andrei Arlou
*/
-@Mapper(componentModel = "jsr330", uses = GenderJsr330DefaultCompileOptionFieldMapper.class)
+@Mapper(componentModel = MappingConstants.ComponentModel.JSR330,
+ uses = GenderJsr330DefaultCompileOptionFieldMapper.class)
public interface CustomerJsr330DefaultCompileOptionFieldMapper {
CustomerDto asTarget(CustomerEntity customerEntity);
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/GenderJsr330DefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/GenderJsr330DefaultCompileOptionFieldMapper.java
index 6701ce42fa..1ecf720cbf 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/GenderJsr330DefaultCompileOptionFieldMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/GenderJsr330DefaultCompileOptionFieldMapper.java
@@ -6,6 +6,7 @@
package org.mapstruct.ap.test.injectionstrategy.jsr330._default;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ValueMapping;
import org.mapstruct.ValueMappings;
import org.mapstruct.ap.test.injectionstrategy.shared.Gender;
@@ -14,7 +15,7 @@
/**
* @author Andrei Arlou
*/
-@Mapper(componentModel = "jsr330")
+@Mapper(componentModel = MappingConstants.ComponentModel.JSR330)
public interface GenderJsr330DefaultCompileOptionFieldMapper {
@ValueMappings({
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java
index 0e89ec8943..143c452886 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java
@@ -7,13 +7,14 @@
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/**
* @author Andrei Arlou
*/
-@Mapper( componentModel = "jsr330",
+@Mapper( componentModel = MappingConstants.ComponentModel.JSR330,
uses = GenderJsr330CompileOptionConstructorMapper.class )
public interface CustomerJsr330CompileOptionConstructorMapper {
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/GenderJsr330CompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/GenderJsr330CompileOptionConstructorMapper.java
index da3caed5be..bffcc06bb9 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/GenderJsr330CompileOptionConstructorMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/GenderJsr330CompileOptionConstructorMapper.java
@@ -6,6 +6,7 @@
package org.mapstruct.ap.test.injectionstrategy.jsr330.compileoptionconstructor;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ValueMapping;
import org.mapstruct.ValueMappings;
import org.mapstruct.ap.test.injectionstrategy.shared.Gender;
@@ -14,7 +15,7 @@
/**
* @author Andrei Arlou
*/
-@Mapper(componentModel = "jsr330")
+@Mapper(componentModel = MappingConstants.ComponentModel.JSR330)
public interface GenderJsr330CompileOptionConstructorMapper {
@ValueMappings({
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java
index 3bfc7d23ae..177b70d1dc 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java
@@ -7,10 +7,12 @@
import org.mapstruct.InjectionStrategy;
import org.mapstruct.MapperConfig;
+import org.mapstruct.MappingConstants;
/**
* @author Filip Hrisafov
*/
-@MapperConfig(componentModel = "jsr330", injectionStrategy = InjectionStrategy.CONSTRUCTOR)
+@MapperConfig(componentModel = MappingConstants.ComponentModel.JSR330,
+ injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface ConstructorJsr330Config {
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java
index 001cb9f736..638e71a3aa 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java
@@ -8,13 +8,14 @@
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/**
* @author Kevin Grüneberg
*/
-@Mapper( componentModel = "jsr330",
+@Mapper( componentModel = MappingConstants.ComponentModel.JSR330,
uses = GenderJsr330ConstructorMapper.class,
injectionStrategy = InjectionStrategy.CONSTRUCTOR )
public interface CustomerJsr330ConstructorMapper {
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java
index 5c53a91c0f..a9e02280a6 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java
@@ -7,13 +7,15 @@
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/**
* @author Kevin Grüneberg
*/
-@Mapper(componentModel = "jsr330", uses = GenderJsr330FieldMapper.class, injectionStrategy = InjectionStrategy.FIELD)
+@Mapper(componentModel = MappingConstants.ComponentModel.JSR330, uses = GenderJsr330FieldMapper.class,
+ injectionStrategy = InjectionStrategy.FIELD)
public interface CustomerJsr330FieldMapper {
CustomerDto asTarget(CustomerEntity customerEntity);
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java
index 33b5bbe8dc..ba3938ae48 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java
@@ -7,10 +7,11 @@
import org.mapstruct.InjectionStrategy;
import org.mapstruct.MapperConfig;
+import org.mapstruct.MappingConstants;
/**
* @author Filip Hrisafov
*/
-@MapperConfig(componentModel = "jsr330", injectionStrategy = InjectionStrategy.FIELD)
+@MapperConfig(componentModel = MappingConstants.ComponentModel.JSR330, injectionStrategy = InjectionStrategy.FIELD)
public interface FieldJsr330Config {
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java
index 34b06fc788..c7c2243d59 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java
@@ -6,13 +6,14 @@
package org.mapstruct.ap.test.injectionstrategy.spring._default;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/**
* @author Filip Hrisafov
*/
-@Mapper(componentModel = "spring", uses = GenderSpringDefaultMapper.class )
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = GenderSpringDefaultMapper.class )
public interface CustomerSpringDefaultMapper {
CustomerDto asTarget(CustomerEntity customerEntity);
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java
index 106b93519e..e49a820994 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java
@@ -6,6 +6,7 @@
package org.mapstruct.ap.test.injectionstrategy.spring._default;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ValueMapping;
import org.mapstruct.ValueMappings;
import org.mapstruct.ap.test.injectionstrategy.shared.Gender;
@@ -14,7 +15,7 @@
/**
* @author Filip Hrisafov
*/
-@Mapper(componentModel = "spring")
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface GenderSpringDefaultMapper {
@ValueMappings({
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerRecordSpringCompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerRecordSpringCompileOptionConstructorMapper.java
index d7debfb96c..f411ba506f 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerRecordSpringCompileOptionConstructorMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerRecordSpringCompileOptionConstructorMapper.java
@@ -6,13 +6,14 @@
package org.mapstruct.ap.test.injectionstrategy.spring.compileoptionconstructor;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity;
/**
* @author Andrei Arlou
*/
-@Mapper(componentModel = "spring",
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING,
uses = { CustomerSpringCompileOptionConstructorMapper.class, GenderSpringCompileOptionConstructorMapper.class },
disableSubMappingMethodsGeneration = true)
public interface CustomerRecordSpringCompileOptionConstructorMapper {
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java
index db11c1b7ad..47060104f7 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java
@@ -7,13 +7,14 @@
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/**
* @author Andrei Arlou
*/
-@Mapper( componentModel = "spring",
+@Mapper( componentModel = MappingConstants.ComponentModel.SPRING,
uses = GenderSpringCompileOptionConstructorMapper.class)
public interface CustomerSpringCompileOptionConstructorMapper {
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/GenderSpringCompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/GenderSpringCompileOptionConstructorMapper.java
index c909f1dc5c..096fe91b96 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/GenderSpringCompileOptionConstructorMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/GenderSpringCompileOptionConstructorMapper.java
@@ -6,6 +6,7 @@
package org.mapstruct.ap.test.injectionstrategy.spring.compileoptionconstructor;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ValueMapping;
import org.mapstruct.ValueMappings;
import org.mapstruct.ap.test.injectionstrategy.shared.Gender;
@@ -14,7 +15,7 @@
/**
* @author Andrei Arlou
*/
-@Mapper(componentModel = "spring")
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface GenderSpringCompileOptionConstructorMapper {
@ValueMappings({
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java
index f4b46e35c3..0bb89895cb 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java
@@ -7,10 +7,12 @@
import org.mapstruct.InjectionStrategy;
import org.mapstruct.MapperConfig;
+import org.mapstruct.MappingConstants;
/**
* @author Filip Hrisafov
*/
-@MapperConfig(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR)
+@MapperConfig(componentModel = MappingConstants.ComponentModel.SPRING,
+ injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface ConstructorSpringConfig {
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerRecordSpringConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerRecordSpringConstructorMapper.java
index a7f9e8a8b2..c2a5862978 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerRecordSpringConstructorMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerRecordSpringConstructorMapper.java
@@ -7,13 +7,14 @@
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity;
/**
* @author Kevin Grüneberg
*/
-@Mapper(componentModel = "spring",
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING,
uses = { CustomerSpringConstructorMapper.class, GenderSpringConstructorMapper.class },
injectionStrategy = InjectionStrategy.CONSTRUCTOR,
disableSubMappingMethodsGeneration = true)
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java
index 9a9ab0119a..4ea869ec5f 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java
@@ -8,13 +8,14 @@
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/**
* @author Kevin Grüneberg
*/
-@Mapper( componentModel = "spring",
+@Mapper( componentModel = MappingConstants.ComponentModel.SPRING,
uses = GenderSpringConstructorMapper.class,
injectionStrategy = InjectionStrategy.CONSTRUCTOR )
public interface CustomerSpringConstructorMapper {
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java
index 449cc5e435..fb8a316c59 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java
@@ -7,13 +7,15 @@
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/**
* @author Kevin Grüneberg
*/
-@Mapper(componentModel = "spring", uses = GenderSpringFieldMapper.class, injectionStrategy = InjectionStrategy.FIELD)
+@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = GenderSpringFieldMapper.class,
+ injectionStrategy = InjectionStrategy.FIELD)
public interface CustomerSpringFieldMapper {
CustomerDto asTarget(CustomerEntity customerEntity);
diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java
index d44a54c935..c9e3c3f0f7 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java
@@ -7,10 +7,11 @@
import org.mapstruct.InjectionStrategy;
import org.mapstruct.MapperConfig;
+import org.mapstruct.MappingConstants;
/**
* @author Filip Hrisafov
*/
-@MapperConfig(componentModel = "spring", injectionStrategy = InjectionStrategy.FIELD)
+@MapperConfig(componentModel = MappingConstants.ComponentModel.SPRING, injectionStrategy = InjectionStrategy.FIELD)
public interface FieldSpringConfig {
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/samename/Jsr330SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/samename/Jsr330SourceTargetMapper.java
index 6d613b0f91..f63b49eef5 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/references/samename/Jsr330SourceTargetMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/references/samename/Jsr330SourceTargetMapper.java
@@ -6,6 +6,7 @@
package org.mapstruct.ap.test.references.samename;
import org.mapstruct.Mapper;
+import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.references.samename.a.CustomMapper;
import org.mapstruct.ap.test.references.samename.model.Source;
import org.mapstruct.ap.test.references.samename.model.Target;
@@ -15,7 +16,7 @@
* @author Gunnar Morling
*/
@Mapper(
- componentModel = "jsr330",
+ componentModel = MappingConstants.ComponentModel.JSR330,
uses = {
CustomMapper.class,
org.mapstruct.ap.test.references.samename.b.CustomMapper.class
From dfc752809604dfcff8bec9d5c1c8f679c9dcae61 Mon Sep 17 00:00:00 2001
From: Filip Hrisafov
Date: Sun, 17 Jan 2021 11:39:57 +0100
Subject: [PATCH 005/471] Small fixes for Java 16
* Upgrade japicmp-maven-plugin to 0.15.2
* Do not use deprecated for removal Long constructor
* Update Spring to 5.3.3
* Upgrade Lombok to 1.18.16 + add lombok-mapstruct-binding
---
integrationtest/pom.xml | 1 -
.../src/test/resources/lombokBuilderTest/pom.xml | 6 ++++++
parent/pom.xml | 8 ++++----
.../mapstruct/ap/test/exceptions/ExceptionTestMapper.java | 2 +-
4 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml
index f19ecfe343..17a6a4a9a9 100644
--- a/integrationtest/pom.xml
+++ b/integrationtest/pom.xml
@@ -65,7 +65,6 @@
commons-iocommons-io
- 2.6test
diff --git a/integrationtest/src/test/resources/lombokBuilderTest/pom.xml b/integrationtest/src/test/resources/lombokBuilderTest/pom.xml
index 92ece809fe..5d43efb1d3 100644
--- a/integrationtest/src/test/resources/lombokBuilderTest/pom.xml
+++ b/integrationtest/src/test/resources/lombokBuilderTest/pom.xml
@@ -25,5 +25,11 @@
lombokcompile
+
+ org.projectlombok
+ lombok-mapstruct-binding
+ 0.2.0
+ compile
+
diff --git a/parent/pom.xml b/parent/pom.xml
index 9e5c04f27a..b6a619a90b 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -25,7 +25,7 @@
3.0.0-M33.0.0-M53.1.0
- 4.0.3.RELEASE
+ 5.3.31.6.08.36.15.7.0
@@ -202,7 +202,7 @@
org.projectlomboklombok
- 1.18.10
+ 1.18.16org.immutables
@@ -261,7 +261,7 @@
commons-iocommons-io
- 2.5
+ 2.6
@@ -553,7 +553,7 @@
com.github.siom79.japicmpjapicmp-maven-plugin
- 0.13.1
+ 0.15.2verify
diff --git a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestMapper.java b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestMapper.java
index c856c0d3bf..13d0d1f5cf 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestMapper.java
@@ -20,6 +20,6 @@ public Long toLong(Integer size) throws TestException1, TestException2 {
else if ( size == 2 ) {
throw new TestException2();
}
- return new Long(size);
+ return Long.valueOf( size );
}
}
From 8478a5455b6dec8da99c1978ac00f0f2605a51c3 Mon Sep 17 00:00:00 2001
From: Sjaak Derksen
Date: Sat, 23 Jan 2021 09:15:46 +0100
Subject: [PATCH 006/471] #2278 inherited property ignored due to ignore on
nested level (#2332)
Co-authored-by: sjaakd
---
.../model/source/MappingMethodOptions.java | 10 +-
.../ap/test/bugs/_2278/Issue2278MapperA.java | 62 ++++++++++
.../ap/test/bugs/_2278/Issue2278MapperB.java | 65 ++++++++++
.../bugs/_2278/Issue2278ReferenceMapper.java | 54 ++++++++
.../ap/test/bugs/_2278/Issue2278Test.java | 95 +++++++++++++++
.../ap/test/bugs/_2318/Issue2318Mapper.java | 115 ++++++++++++++++++
.../ap/test/bugs/_2318/Issue2318Test.java | 38 ++++++
7 files changed, 435 insertions(+), 4 deletions(-)
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperA.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperB.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278ReferenceMapper.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278Test.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Mapper.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Test.java
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java
index b7fd7f00d0..859a4c6f5f 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java
@@ -230,9 +230,11 @@ private void addAllNonRedefined(Set inheritedMappings) {
}
private boolean isRedefined(Set redefinedNames, String inheritedName ) {
- for ( String redefinedName : redefinedNames ) {
- if ( elementsAreContainedIn( redefinedName, inheritedName ) ) {
- return true;
+ if ( inheritedName != null ) {
+ for ( String redefinedName : redefinedNames ) {
+ if ( elementsAreContainedIn( inheritedName, redefinedName ) ) {
+ return true;
+ }
}
}
return false;
@@ -241,7 +243,7 @@ private boolean isRedefined(Set redefinedNames, String inheritedName ) {
private boolean elementsAreContainedIn( String redefinedName, String inheritedName ) {
if ( inheritedName != null && redefinedName.startsWith( inheritedName ) ) {
// it is possible to redefine an exact matching source name, because the same source can be mapped to
- // multiple targets. It is not possible for target, but caught by the Set and equals methoded in
+ // multiple targets. It is not possible for target, but caught by the Set and equals method in
// MappingOptions. SourceName == null also could hint at redefinition
if ( redefinedName.length() > inheritedName.length() ) {
// redefined.lenght() > inherited.length(), first following character should be separator
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperA.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperA.java
new file mode 100644
index 0000000000..8527be3f89
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperA.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2278;
+
+import org.mapstruct.InheritInverseConfiguration;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * ReproducerA
+ *
+ */
+@Mapper
+public interface Issue2278MapperA {
+
+ Issue2278MapperA INSTANCE = Mappers.getMapper( Issue2278MapperA.class );
+
+ @Mapping( target = "detailsDTO", source = "details" )
+ @Mapping( target = "detailsDTO.fuelType", ignore = true )
+ CarDTO map(Car in);
+
+ // checkout the Issue2278ReferenceMapper, the @InheritInverseConfiguration
+ // is de-facto @Mapping( target = "details", source = "detailsDTO" )
+ @InheritInverseConfiguration
+ @Mapping( target = "details.model", ignore = true )
+ @Mapping( target = "details.type", constant = "gto")
+ @Mapping( target = "details.fuel", source = "detailsDTO.fuelType")
+ Car map(CarDTO in);
+
+ class Car {
+ //CHECKSTYLE:OFF
+ public Details details;
+ //CHECKSTYLE:ON
+ }
+
+ class CarDTO {
+ //CHECKSTYLE:OFF
+ public DetailsDTO detailsDTO;
+ //CHECKSTYLE:ON
+ }
+
+ class Details {
+ //CHECKSTYLE:OFF
+ public String brand;
+ public String model;
+ public String type;
+ public String fuel;
+ //CHECKSTYLE:ON
+ }
+
+ class DetailsDTO {
+ //CHECKSTYLE:OFF
+ public String brand;
+ public String fuelType;
+ //CHECKSTYLE:ON
+ }
+
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperB.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperB.java
new file mode 100644
index 0000000000..b9d0abd523
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperB.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2278;
+
+import org.mapstruct.InheritInverseConfiguration;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * ReproducerB
+ *
+ */
+@Mapper
+public interface Issue2278MapperB {
+
+ Issue2278MapperB INSTANCE = Mappers.getMapper( Issue2278MapperB.class );
+
+ // id mapping is cros-linked
+ @Mapping( target = "amount", source = "price" )
+ @Mapping( target = "detailsDTO.brand", source = "details.type" )
+ @Mapping( target = "detailsDTO.id1", source = "details.id2" )
+ @Mapping( target = "detailsDTO.id2", source = "details.id1" )
+ CarDTO map(Car in);
+
+ // inherit inverse, but undo cross-link in one sweep
+ @InheritInverseConfiguration // inherits all
+ @Mapping( target = "details", source = "detailsDTO" ) // resets everything on details <> detailsDto
+ @Mapping( target = "details.type", source = "detailsDTO.brand" ) // so this needs to be redone
+ Car map2(CarDTO in);
+
+ class Car {
+ //CHECKSTYLE:OFF
+ public float price;
+ public Details details;
+ //CHECKSTYLE:ON
+ }
+
+ class CarDTO {
+ //CHECKSTYLE:OFF
+ public float amount;
+ public DetailsDTO detailsDTO;
+ //CHECKSTYLE:ON
+ }
+
+ class Details {
+ //CHECKSTYLE:OFF
+ public String type;
+ public String id1;
+ public String id2;
+ //CHECKSTYLE:ON
+ }
+
+ class DetailsDTO {
+ //CHECKSTYLE:OFF
+ public String brand;
+ public String id1;
+ public String id2;
+ //CHECKSTYLE:ON
+ }
+
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278ReferenceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278ReferenceMapper.java
new file mode 100644
index 0000000000..48b457f84c
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278ReferenceMapper.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2278;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * A reference mapper, that checks how a regular forward merge works
+ */
+@Mapper
+public interface Issue2278ReferenceMapper {
+
+ Issue2278ReferenceMapper INSTANCE = Mappers.getMapper( Issue2278ReferenceMapper.class );
+
+ @Mapping( target = "details", source = "detailsDTO" )
+ @Mapping( target = "details.model", ignore = true )
+ @Mapping( target = "details.type", constant = "gto")
+ @Mapping( target = "details.fuel", source = "detailsDTO.fuelType")
+ Car map(CarDTO in);
+
+ class Car {
+ //CHECKSTYLE:OFF
+ public Details details;
+ //CHECKSTYLE:ON
+ }
+
+ class CarDTO {
+ //CHECKSTYLE:OFF
+ public DetailsDTO detailsDTO;
+ //CHECKSTYLE:ON
+ }
+
+ class Details {
+ //CHECKSTYLE:OFF
+ public String brand;
+ public String model;
+ public String type;
+ public String fuel;
+ //CHECKSTYLE:ON
+ }
+
+ class DetailsDTO {
+ //CHECKSTYLE:OFF
+ public String brand;
+ public String fuelType;
+ //CHECKSTYLE:ON
+ }
+
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278Test.java
new file mode 100644
index 0000000000..eefebfa870
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278Test.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2278;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mapstruct.ap.testutil.IssueKey;
+import org.mapstruct.ap.testutil.WithClasses;
+import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
+
+@IssueKey("2278")
+@RunWith( AnnotationProcessorTestRunner.class)
+public class Issue2278Test {
+
+ @Test
+ @WithClasses( Issue2278ReferenceMapper.class )
+ public void testReferenceMergeBehaviour() {
+
+ Issue2278ReferenceMapper.CarDTO dto = new Issue2278ReferenceMapper.CarDTO();
+ dto.detailsDTO = new Issue2278ReferenceMapper.DetailsDTO();
+ dto.detailsDTO.brand = "Ford";
+ dto.detailsDTO.fuelType = "petrol";
+
+ Issue2278ReferenceMapper.Car target = Issue2278ReferenceMapper.INSTANCE.map( dto );
+
+ assertThat( target ).isNotNull();
+ assertThat( target.details ).isNotNull();
+ assertThat( target.details.brand ).isEqualTo( "Ford" );
+ assertThat( target.details.model ).isNull();
+ assertThat( target.details.type ).isEqualTo( "gto" );
+ assertThat( target.details.fuel ).isEqualTo( "petrol" );
+
+ }
+
+ @Test
+ @WithClasses( Issue2278MapperA.class )
+ public void shouldBehaveJustAsTestReferenceMergeBehaviour() {
+
+ Issue2278MapperA.CarDTO dto = new Issue2278MapperA.CarDTO();
+ dto.detailsDTO = new Issue2278MapperA.DetailsDTO();
+ dto.detailsDTO.brand = "Ford";
+ dto.detailsDTO.fuelType = "petrol";
+
+ Issue2278MapperA.Car target = Issue2278MapperA.INSTANCE.map( dto );
+
+ assertThat( target ).isNotNull();
+ assertThat( target.details ).isNotNull();
+ assertThat( target.details.brand ).isEqualTo( "Ford" );
+ assertThat( target.details.model ).isNull();
+ assertThat( target.details.type ).isEqualTo( "gto" );
+ assertThat( target.details.fuel ).isEqualTo( "petrol" );
+
+ }
+
+ @Test
+ @WithClasses( Issue2278MapperB.class )
+ public void shouldOverrideDetailsMappingWithRedefined() {
+
+ Issue2278MapperB.Car source = new Issue2278MapperB.Car();
+ source.details = new Issue2278MapperB.Details();
+ source.details.type = "Ford";
+ source.details.id1 = "id1";
+ source.details.id2 = "id2";
+ source.price = 20000f;
+
+ Issue2278MapperB.CarDTO target1 = Issue2278MapperB.INSTANCE.map( source );
+
+ assertThat( target1 ).isNotNull();
+ assertThat( target1.amount ).isEqualTo( 20000f );
+ assertThat( target1.detailsDTO ).isNotNull();
+ assertThat( target1.detailsDTO.brand ).isEqualTo( "Ford" );
+ assertThat( target1.detailsDTO.id1 ).isEqualTo( "id2" );
+ assertThat( target1.detailsDTO.id2 ).isEqualTo( "id1" );
+
+ // restore the mappings, just to make it logical again
+ target1.detailsDTO.id1 = "id1";
+ target1.detailsDTO.id2 = "id2";
+
+ // now check the reverse inheritance
+ Issue2278MapperB.Car target2 = Issue2278MapperB.INSTANCE.map2( target1 );
+
+ assertThat( target2 ).isNotNull();
+ assertThat( target2.price ).isEqualTo( 20000f );
+ assertThat( target2.details ).isNotNull();
+ assertThat( target2.details.type ).isEqualTo( "Ford" ); // should inherit
+ assertThat( target2.details.id1 ).isEqualTo( "id1" ); // should be undone
+ assertThat( target2.details.id2 ).isEqualTo( "id2" ); // should be undone
+ }
+
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Mapper.java
new file mode 100644
index 0000000000..20621e4d01
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Mapper.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2318;
+
+import org.mapstruct.InheritConfiguration;
+import org.mapstruct.Mapper;
+import org.mapstruct.MapperConfig;
+import org.mapstruct.Mapping;
+import org.mapstruct.factory.Mappers;
+
+@Mapper(config = Issue2318Mapper.Config.class)
+public interface Issue2318Mapper {
+
+ Issue2318Mapper INSTANCE = Mappers.getMapper( Issue2318Mapper.class );
+
+ @MapperConfig
+ interface Config {
+
+ @Mapping(target = "parentValue1", source = "holder")
+ TargetParent mapParent(SourceParent parent);
+
+ @InheritConfiguration(name = "mapParent")
+ @Mapping(target = "childValue", source = "value")
+ @Mapping(target = "parentValue2", source = "holder.parentValue2")
+ TargetChild mapChild(SourceChild child);
+ }
+
+ @InheritConfiguration(name = "mapChild")
+ TargetChild mapChild(SourceChild child);
+
+ default String parentValue1(SourceParent.Holder holder) {
+ return holder.getParentValue1();
+ }
+
+ class SourceParent {
+ private Holder holder;
+
+ public Holder getHolder() {
+ return holder;
+ }
+
+ public void setHolder(Holder holder) {
+ this.holder = holder;
+ }
+
+ public static class Holder {
+ private String parentValue1;
+ private Integer parentValue2;
+
+ public String getParentValue1() {
+ return parentValue1;
+ }
+
+ public void setParentValue1(String parentValue1) {
+ this.parentValue1 = parentValue1;
+ }
+
+ public Integer getParentValue2() {
+ return parentValue2;
+ }
+
+ public void setParentValue2(Integer parentValue2) {
+ this.parentValue2 = parentValue2;
+ }
+ }
+ }
+
+ class SourceChild extends SourceParent {
+ private String value;
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+ }
+
+ class TargetParent {
+ private String parentValue1;
+ private Integer parentValue2;
+
+ public String getParentValue1() {
+ return parentValue1;
+ }
+
+ public void setParentValue1(String parentValue1) {
+ this.parentValue1 = parentValue1;
+ }
+
+ public Integer getParentValue2() {
+ return parentValue2;
+ }
+
+ public void setParentValue2(Integer parentValue2) {
+ this.parentValue2 = parentValue2;
+ }
+ }
+
+ class TargetChild extends TargetParent {
+ private String childValue;
+
+ public String getChildValue() {
+ return childValue;
+ }
+
+ public void setChildValue(String childValue) {
+ this.childValue = childValue;
+ }
+ }
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Test.java
new file mode 100644
index 0000000000..a1f1ad250b
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Test.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2318;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mapstruct.ap.test.bugs._2318.Issue2318Mapper.SourceChild;
+import org.mapstruct.ap.test.bugs._2318.Issue2318Mapper.TargetChild;
+import org.mapstruct.ap.testutil.IssueKey;
+import org.mapstruct.ap.testutil.WithClasses;
+import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@IssueKey("2318")
+@RunWith(AnnotationProcessorTestRunner.class)
+public class Issue2318Test {
+
+ @Test
+ @WithClasses( Issue2318Mapper.class )
+ public void shouldMap() {
+
+ SourceChild source = new SourceChild();
+ source.setValue( "From child" );
+ source.setHolder( new Issue2318Mapper.SourceParent.Holder() );
+ source.getHolder().setParentValue1( "From parent" );
+ source.getHolder().setParentValue2( 12 );
+
+ TargetChild target = Issue2318Mapper.INSTANCE.mapChild( source );
+
+ assertThat( target.getParentValue1() ).isEqualTo( "From parent" );
+ assertThat( target.getParentValue2() ).isEqualTo( 12 );
+ assertThat( target.getChildValue() ).isEqualTo( "From child" );
+ }
+}
From 0d8bbacc53bfd101015a5d8860d67a3c2d71ea1c Mon Sep 17 00:00:00 2001
From: Filip Hrisafov
Date: Sat, 16 Jan 2021 19:43:22 +0100
Subject: [PATCH 007/471] #2250, #2324 Do not throw error when qualifier is
missing on iterable mapping
With this change we are relaxing the error handling when qualifiers are used in `@Mapping`
and we allow defining qualifiers for collections / array mapping to mean the same as if it was defined on `@IterableMapping`
i.e. apply the qualifier on the element mapping
---
.../model/ContainerMappingMethodBuilder.java | 10 +++-
.../ap/internal/model/PropertyMapping.java | 1 +
.../creation/MappingResolverImpl.java | 8 +++-
...neousMessageByNamedWithIterableMapper.java | 31 ++++++++++++
.../qualifier/errors/QualfierMessageTest.java | 23 +++++++++
.../selection/qualifier/iterable/Cities.java | 23 +++++++++
.../iterable/IterableAndQualifiersTest.java | 40 +++++++++++++++-
.../selection/qualifier/iterable/Rivers.java | 23 +++++++++
.../qualifier/iterable/TopologyMapper.java | 17 -------
.../TopologyWithoutIterableMappingMapper.java | 47 +++++++++++++++++++
10 files changed, 203 insertions(+), 20 deletions(-)
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByNamedWithIterableMapper.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Cities.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Rivers.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyWithoutIterableMappingMapper.java
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java
index b9bbf6d094..be08ac1ca4 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java
@@ -22,6 +22,8 @@
import static org.mapstruct.ap.internal.util.Collections.first;
+import javax.lang.model.element.AnnotationMirror;
+
/**
* Builder that can be used to build {@link ContainerMappingMethod}(s).
*
@@ -37,6 +39,7 @@ public abstract class ContainerMappingMethodBuilder selfType, String errorMessagePart) {
super( selfType );
@@ -58,6 +61,11 @@ public B callingContextTargetPropertyName(String callingContextTargetPropertyNam
return myself;
}
+ public B positionHint(AnnotationMirror positionHint) {
+ this.positionHint = positionHint;
+ return myself;
+ }
+
@Override
public final M build() {
Type sourceParameterType = first( method.getSourceParameters() ).getType();
@@ -88,7 +96,7 @@ public final M build() {
formattingParameters,
criteria,
sourceRHS,
- null,
+ positionHint,
() -> forge( sourceRHS, sourceElementType, targetElementType )
);
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java
index 61e1fca864..48ebc34d29 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java
@@ -656,6 +656,7 @@ private Assignment forgeWithElementMapping(Type sourceType, Type targetType, Sou
.method( methodRef )
.selectionParameters( selectionParameters )
.callingContextTargetPropertyName( targetPropertyName )
+ .positionHint( positionHint )
.build();
return createForgedAssignment( source, methodRef, iterableMappingMethod );
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java
index debe8f30dc..5f9121082c 100755
--- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java
@@ -298,7 +298,13 @@ && allowDirect( sourceType, targetType ) ) {
}
if ( hasQualfiers() ) {
- printQualifierMessage( selectionCriteria );
+ if ((sourceType.isCollectionType() || sourceType.isArrayType()) && targetType.isIterableType()) {
+ // Allow forging iterable mapping when no iterable mapping already found
+ return forger.get();
+ }
+ else {
+ printQualifierMessage( selectionCriteria );
+ }
}
else if ( allowMappingMethod() ) {
// only forge if we would allow mapping method
diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByNamedWithIterableMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByNamedWithIterableMapper.java
new file mode 100644
index 0000000000..088207c610
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByNamedWithIterableMapper.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.selection.qualifier.errors;
+
+import java.util.Collection;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+
+@Mapper
+public interface ErroneousMessageByNamedWithIterableMapper {
+
+ @Mapping(target = "elements", qualifiedByName = "SelectMe")
+ Target map(Source source);
+
+ // CHECKSTYLE:OFF
+ class Source {
+
+ public Collection elements;
+ }
+
+ class Target {
+
+ public Collection elements;
+ }
+ // CHECKSTYLE ON
+
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java
index 4c8edc64dd..48295ed4fb 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java
@@ -87,4 +87,27 @@ public void testNoQualifyingMethodByNamedFound() {
)
public void testNoQualifyingMethodByAnnotationAndNamedFound() {
}
+
+ @Test
+ @WithClasses(ErroneousMessageByNamedWithIterableMapper.class)
+ @ExpectedCompilationOutcome(
+ value = CompilationResult.FAILED,
+ diagnostics = {
+ @Diagnostic(
+ type = ErroneousMessageByNamedWithIterableMapper.class,
+ kind = ERROR,
+ line = 16,
+ message = "Qualifier error. No method found annotated with @Named#value: [ SelectMe ]. " +
+ "See https://mapstruct.org/faq/#qualifier for more info."),
+ @Diagnostic(
+ type = ErroneousMessageByNamedWithIterableMapper.class,
+ kind = ERROR,
+ line = 16,
+ messageRegExp = "Can't map property.*"),
+
+ }
+ )
+ public void testNoQualifyingMethodByNamedForForgedIterableFound() {
+ }
+
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Cities.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Cities.java
new file mode 100644
index 0000000000..828750399a
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Cities.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.selection.qualifier.iterable;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.mapstruct.Qualifier;
+
+/**
+ * @author Filip Hrisafov
+ */
+@Qualifier
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.CLASS)
+public @interface Cities {
+
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java
index db8de9496e..c2465b255e 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java
@@ -15,6 +15,7 @@
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
+import org.mapstruct.factory.Mappers;
/**
*
@@ -22,20 +23,22 @@
*/
@IssueKey( "707" )
@WithClasses( {
+ Cities.class,
CityDto.class,
CityEntity.class,
RiverDto.class,
RiverEntity.class,
+ Rivers.class,
TopologyDto.class,
TopologyEntity.class,
TopologyFeatureDto.class,
TopologyFeatureEntity.class,
- TopologyMapper.class
} )
@RunWith( AnnotationProcessorTestRunner.class )
public class IterableAndQualifiersTest {
@Test
+ @WithClasses(TopologyMapper.class)
public void testGenerationBasedOnQualifier() {
TopologyDto topologyDto1 = new TopologyDto();
@@ -67,4 +70,39 @@ public void testGenerationBasedOnQualifier() {
assertThat( ( (CityEntity) result2.getTopologyFeatures().get( 0 ) ).getPopulation() ).isEqualTo( 800000 );
}
+
+ @Test
+ @WithClasses(TopologyWithoutIterableMappingMapper.class)
+ public void testIterableGeneratorBasedOnQualifier() {
+
+ TopologyWithoutIterableMappingMapper mapper = Mappers.getMapper( TopologyWithoutIterableMappingMapper.class );
+
+ TopologyDto riverTopologyDto = new TopologyDto();
+ List topologyFeatures1 = new ArrayList<>();
+ RiverDto riverDto = new RiverDto();
+ riverDto.setName( "Rhine" );
+ riverDto.setLength( 5 );
+ topologyFeatures1.add( riverDto );
+ riverTopologyDto.setTopologyFeatures( topologyFeatures1 );
+
+ TopologyEntity riverTopology = mapper.mapTopologyAsRiver( riverTopologyDto );
+ assertThat( riverTopology.getTopologyFeatures() ).hasSize( 1 );
+ assertThat( riverTopology.getTopologyFeatures().get( 0 ).getName() ).isEqualTo( "Rhine" );
+ assertThat( riverTopology.getTopologyFeatures().get( 0 ) ).isInstanceOf( RiverEntity.class );
+ assertThat( ( (RiverEntity) riverTopology.getTopologyFeatures().get( 0 ) ).getLength() ).isEqualTo( 5 );
+
+ TopologyDto cityTopologyDto = new TopologyDto();
+ List topologyFeatures2 = new ArrayList<>();
+ CityDto cityDto = new CityDto();
+ cityDto.setName( "Amsterdam" );
+ cityDto.setPopulation( 800000 );
+ topologyFeatures2.add( cityDto );
+ cityTopologyDto.setTopologyFeatures( topologyFeatures2 );
+
+ TopologyEntity cityTopology = mapper.mapTopologyAsCity( cityTopologyDto );
+ assertThat( cityTopology.getTopologyFeatures() ).hasSize( 1 );
+ assertThat( cityTopology.getTopologyFeatures().get( 0 ).getName() ).isEqualTo( "Amsterdam" );
+ assertThat( cityTopology.getTopologyFeatures().get( 0 ) ).isInstanceOf( CityEntity.class );
+ assertThat( ( (CityEntity) cityTopology.getTopologyFeatures().get( 0 ) ).getPopulation() ).isEqualTo( 800000 );
+ }
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Rivers.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Rivers.java
new file mode 100644
index 0000000000..f6a56951a1
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Rivers.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.selection.qualifier.iterable;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.mapstruct.Qualifier;
+
+/**
+ * @author Filip Hrisafov
+ */
+@Qualifier
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.CLASS)
+public @interface Rivers {
+
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java
index 22e87dd084..84c4bc58a1 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java
@@ -5,16 +5,11 @@
*/
package org.mapstruct.ap.test.selection.qualifier.iterable;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
import java.util.List;
import org.mapstruct.IterableMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
-import org.mapstruct.Qualifier;
import org.mapstruct.factory.Mappers;
/**
@@ -64,16 +59,4 @@ protected TopologyFeatureEntity mapCity( TopologyFeatureDto dto ) {
return topologyFeatureEntity;
}
- @Qualifier
- @Target(ElementType.METHOD)
- @Retention(RetentionPolicy.CLASS)
- public @interface Rivers {
- }
-
- @Qualifier
- @Target(ElementType.METHOD)
- @Retention(RetentionPolicy.CLASS)
- public @interface Cities {
- }
-
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyWithoutIterableMappingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyWithoutIterableMappingMapper.java
new file mode 100644
index 0000000000..4b72b34663
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyWithoutIterableMappingMapper.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.selection.qualifier.iterable;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+
+/**
+ * @author Filip Hrisafov
+ */
+@Mapper
+public interface TopologyWithoutIterableMappingMapper {
+
+ @Mapping( target = "topologyFeatures", qualifiedBy = Rivers.class )
+ TopologyEntity mapTopologyAsRiver(TopologyDto dto);
+
+ @Mapping( target = "topologyFeatures", qualifiedBy = Cities.class )
+ TopologyEntity mapTopologyAsCity(TopologyDto dto);
+
+ @Rivers
+ default TopologyFeatureEntity mapRiver( TopologyFeatureDto dto ) {
+ TopologyFeatureEntity topologyFeatureEntity = null;
+ if ( dto instanceof RiverDto ) {
+ RiverEntity riverEntity = new RiverEntity();
+ riverEntity.setLength( ( (RiverDto) dto ).getLength() );
+ topologyFeatureEntity = riverEntity;
+ topologyFeatureEntity.setName( dto.getName() );
+ }
+ return topologyFeatureEntity;
+ }
+
+ @Cities
+ default TopologyFeatureEntity mapCity( TopologyFeatureDto dto ) {
+ TopologyFeatureEntity topologyFeatureEntity = null;
+ if ( dto instanceof CityDto ) {
+ CityEntity cityEntity = new CityEntity();
+ cityEntity.setPopulation( ( (CityDto) dto ).getPopulation() );
+ topologyFeatureEntity = cityEntity;
+ topologyFeatureEntity.setName( dto.getName() );
+ }
+ return topologyFeatureEntity;
+ }
+
+}
From 08af258533c6f949de8b0e1a71fb79beab895b5a Mon Sep 17 00:00:00 2001
From: Filip Hrisafov
Date: Sat, 30 Jan 2021 10:35:04 +0100
Subject: [PATCH 008/471] #2346 Update documentation and readme about MapStruct
and Gradle
Remove obsolete net.ltgt.apt
Use com.diffplug.eclipse.apt for Eclipse
IntelliJ works transparently
---
.../main/asciidoc/chapter-2-set-up.asciidoc | 36 ++-----------------
readme.md | 7 +---
2 files changed, 3 insertions(+), 40 deletions(-)
diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc
index cb0067f2f3..76626f44ce 100644
--- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc
+++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc
@@ -76,7 +76,7 @@ It will not work with older versions.
Add the following to your Gradle build file in order to enable MapStruct:
-.Gradle configuration (3.4 and later)
+.Gradle configuration
====
[source, groovy, linenums]
[subs="verbatim,attributes"]
@@ -84,14 +84,9 @@ Add the following to your Gradle build file in order to enable MapStruct:
...
plugins {
...
- id 'net.ltgt.apt' version '0.20'
+ id "com.diffplug.eclipse.apt" version "3.26.0" // Only for Eclipse
}
-// You can integrate with your IDEs.
-// See more details: https://github.com/tbroyer/gradle-apt-plugin#usage-with-ides
-apply plugin: 'net.ltgt.apt-idea'
-apply plugin: 'net.ltgt.apt-eclipse'
-
dependencies {
...
implementation "org.mapstruct:mapstruct:${mapstructVersion}"
@@ -103,33 +98,6 @@ dependencies {
...
----
====
-.Gradle (3.3 and older)
-====
-[source, groovy, linenums]
-[subs="verbatim,attributes"]
-----
-...
-plugins {
- ...
- id 'net.ltgt.apt' version '0.20'
-}
-
-// You can integrate with your IDEs.
-// See more details: https://github.com/tbroyer/gradle-apt-plugin#usage-with-ides
-apply plugin: 'net.ltgt.apt-idea'
-apply plugin: 'net.ltgt.apt-eclipse'
-
-dependencies {
- ...
- compile "org.mapstruct:mapstruct:${mapstructVersion}"
- annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
-
- // If you are using mapstruct in test code
- testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
-}
-...
-----
-====
You can find a complete example in the https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-on-gradle[mapstruct-examples] project on GitHub.
diff --git a/readme.md b/readme.md
index c39a408ac2..45eeda27e6 100644
--- a/readme.md
+++ b/readme.md
@@ -109,14 +109,9 @@ For Gradle, you need something along the following lines:
```groovy
plugins {
...
- id 'net.ltgt.apt' version '0.15'
+ id "com.diffplug.eclipse.apt" version "3.26.0" // Only for Eclipse
}
-// You can integrate with your IDEs.
-// See more details: https://github.com/tbroyer/gradle-apt-plugin#usage-with-ides
-apply plugin: 'net.ltgt.apt-idea'
-apply plugin: 'net.ltgt.apt-eclipse'
-
dependencies {
...
compile 'org.mapstruct:mapstruct:1.4.1.Final'
From aeadf8cb77978334619e40801faed25e5eaa54b3 Mon Sep 17 00:00:00 2001
From: Filip Hrisafov
Date: Sun, 31 Jan 2021 14:52:11 +0100
Subject: [PATCH 009/471] Update readme with latest released 1.4.2.Final
release
---
readme.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/readme.md b/readme.md
index 45eeda27e6..5fc8399748 100644
--- a/readme.md
+++ b/readme.md
@@ -1,6 +1,6 @@
# MapStruct - Java bean mappings, the easy way!
-[](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final)
+[](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final)
[](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct)
[](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt)
@@ -68,7 +68,7 @@ For Maven-based projects, add the following to your POM file in order to use Map
```xml
...
- 1.4.1.Final
+ 1.4.2.Final
...
@@ -114,10 +114,10 @@ plugins {
dependencies {
...
- compile 'org.mapstruct:mapstruct:1.4.1.Final'
+ compile 'org.mapstruct:mapstruct:1.4.2.Final'
- annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.1.Final'
- testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.4.1.Final' // if you are using mapstruct in test code
+ annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
+ testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' // if you are using mapstruct in test code
}
...
```
From c59ca79e7f992d051661fa2d39eb1cbee014b116 Mon Sep 17 00:00:00 2001
From: dmngb <26900086+dmngb@users.noreply.github.com>
Date: Sat, 6 Feb 2021 16:10:32 +0100
Subject: [PATCH 010/471] #2277 default component model: mapper reference use
singleton INSTANCE if it exists (#2280)
This allows to easily avoid the runtime dependency on mapstruct.jar:
we can avoid Mappers.getMapper(...) for instantiating used mappers if
the code follows the conventional pattern for creating mapper singletons.
Co-authored-by: GIBOU Damien
---
.../model/DefaultMapperReference.java | 18 +++++++++----
.../processor/MapperCreationProcessor.java | 26 +++++++++++++++++++
.../internal/model/DefaultMapperReference.ftl | 2 +-
.../selection/OrganizationMapper1Impl.java | 3 +--
.../selection/OrganizationMapper3Impl.java | 3 +--
5 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java
index 924648368a..6ac0c1c74d 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java
@@ -21,19 +21,22 @@
*/
public class DefaultMapperReference extends MapperReference {
+ private final boolean isSingleton;
private final boolean isAnnotatedMapper;
private final Set importTypes;
- private DefaultMapperReference(Type type, boolean isAnnotatedMapper, Set importTypes, String variableName) {
+ private DefaultMapperReference(Type type, boolean isAnnotatedMapper, boolean isSingleton,
+ Set importTypes, String variableName) {
super( type, variableName );
this.isAnnotatedMapper = isAnnotatedMapper;
this.importTypes = importTypes;
+ this.isSingleton = isSingleton;
}
- public static DefaultMapperReference getInstance(Type type, boolean isAnnotatedMapper, TypeFactory typeFactory,
- List otherMapperReferences) {
+ public static DefaultMapperReference getInstance(Type type, boolean isAnnotatedMapper, boolean isSingleton,
+ TypeFactory typeFactory, List otherMapperReferences) {
Set importTypes = Collections.asSet( type );
- if ( isAnnotatedMapper ) {
+ if ( isAnnotatedMapper && !isSingleton) {
importTypes.add( typeFactory.getType( "org.mapstruct.factory.Mappers" ) );
}
@@ -42,7 +45,7 @@ public static DefaultMapperReference getInstance(Type type, boolean isAnnotatedM
otherMapperReferences
);
- return new DefaultMapperReference( type, isAnnotatedMapper, importTypes, variableName );
+ return new DefaultMapperReference( type, isAnnotatedMapper, isSingleton, importTypes, variableName );
}
@Override
@@ -53,4 +56,9 @@ public Set getImportTypes() {
public boolean isAnnotatedMapper() {
return isAnnotatedMapper;
}
+
+ public boolean isSingleton() {
+ return isSingleton;
+ }
+
}
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java
index a0014f5934..ad6d84b9e9 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java
@@ -6,6 +6,7 @@
package org.mapstruct.ap.internal.processor;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.LinkedList;
@@ -13,7 +14,9 @@
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
+import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
@@ -60,6 +63,9 @@
import org.mapstruct.ap.internal.util.Strings;
import org.mapstruct.ap.internal.version.VersionInformation;
+import static javax.lang.model.element.Modifier.FINAL;
+import static javax.lang.model.element.Modifier.PUBLIC;
+import static javax.lang.model.element.Modifier.STATIC;
import static org.mapstruct.ap.internal.model.SupportingConstructorFragment.addAllFragmentsIn;
import static org.mapstruct.ap.internal.model.SupportingField.addAllFieldsIn;
import static org.mapstruct.ap.internal.util.Collections.first;
@@ -73,6 +79,9 @@
*/
public class MapperCreationProcessor implements ModelElementProcessor, Mapper> {
+ /** Modifiers for public "constant" e.g. "public static final" */
+ private static final List PUBLIC_CONSTANT_MODIFIERS = Arrays.asList( PUBLIC, STATIC, FINAL );
+
private ElementUtils elementUtils;
private TypeUtils typeUtils;
private FormattingMessager messager;
@@ -136,6 +145,7 @@ private List initReferencedMappers(TypeElement element, MapperO
DefaultMapperReference mapperReference = DefaultMapperReference.getInstance(
typeFactory.getType( usedMapper ),
MapperGem.instanceOn( typeUtils.asElement( usedMapper ) ) != null,
+ hasSingletonInstance( usedMapper ),
typeFactory,
variableNames
);
@@ -147,6 +157,22 @@ private List initReferencedMappers(TypeElement element, MapperO
return result;
}
+ private boolean hasSingletonInstance(TypeMirror mapper) {
+ return typeUtils.asElement( mapper ).getEnclosedElements().stream()
+ .anyMatch( a -> isPublicConstantOfType( a, "INSTANCE", mapper ) );
+ }
+
+ /**
+ * @return true if the element is a "public static final" field (e.g. a constant)
+ * named fieldName of type "fieldType"
+ */
+ private boolean isPublicConstantOfType(Element element, String fieldName, TypeMirror fieldType) {
+ return element.getKind().isField() &&
+ element.getModifiers().containsAll( PUBLIC_CONSTANT_MODIFIERS ) &&
+ element.getSimpleName().contentEquals( fieldName ) &&
+ typeUtils.isSameType( element.asType(), fieldType );
+ }
+
private Mapper getMapper(TypeElement element, MapperOptions mapperOptions, List methods) {
List mappingMethods = getMappingMethods( mapperOptions, methods );
diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl
index e4eeddb4b5..b2ab4cb6f0 100644
--- a/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl
+++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl
@@ -6,4 +6,4 @@
-->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DefaultMapperReference" -->
-private final <@includeModel object=type/> ${variableName} = <#if annotatedMapper>Mappers.getMapper( <@includeModel object=type/>.class );<#else>new <@includeModel object=type/>();#if>
\ No newline at end of file
+private final <@includeModel object=type/> ${variableName} = <#if singleton><@includeModel object=type/>.INSTANCE;<#else><#if annotatedMapper>Mappers.getMapper( <@includeModel object=type/>.class );<#else>new <@includeModel object=type/>();#if>#if>
\ No newline at end of file
diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java
index 7e53df87c4..98f603d365 100644
--- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java
+++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java
@@ -9,7 +9,6 @@
import org.mapstruct.ap.test.updatemethods.CompanyDto;
import org.mapstruct.ap.test.updatemethods.CompanyEntity;
import org.mapstruct.ap.test.updatemethods.DepartmentEntityFactory;
-import org.mapstruct.factory.Mappers;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
@@ -18,7 +17,7 @@
)
public class OrganizationMapper1Impl implements OrganizationMapper1 {
- private final ExternalMapper externalMapper = Mappers.getMapper( ExternalMapper.class );
+ private final ExternalMapper externalMapper = ExternalMapper.INSTANCE;
private final DepartmentEntityFactory departmentEntityFactory = new DepartmentEntityFactory();
@Override
diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java
index 11c3bd0df6..76b2d3d9e8 100644
--- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java
+++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java
@@ -9,7 +9,6 @@
import org.mapstruct.ap.test.updatemethods.BossDto;
import org.mapstruct.ap.test.updatemethods.BossEntity;
import org.mapstruct.ap.test.updatemethods.ConstructableDepartmentEntity;
-import org.mapstruct.factory.Mappers;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
@@ -18,7 +17,7 @@
)
public class OrganizationMapper3Impl implements OrganizationMapper3 {
- private final ExternalMapper externalMapper = Mappers.getMapper( ExternalMapper.class );
+ private final ExternalMapper externalMapper = ExternalMapper.INSTANCE;
@Override
public void toBossEntity(BossDto dto, BossEntity entity) {
From b643061b57f39dbf75d7142ec7b9144ed184331b Mon Sep 17 00:00:00 2001
From: Filip Hrisafov
Date: Sat, 6 Feb 2021 16:27:24 +0100
Subject: [PATCH 011/471] #2277 Add tests with fixtures with testing the
generated source code
---
.../DefaultComponentModelMapperTest.java | 46 +++++++++++++++++++
.../InstanceIterableMapper.java | 19 ++++++++
.../defaultcomponentmodel/InstanceMapper.java | 20 ++++++++
.../NonInstanceIterableMapper.java | 19 ++++++++
.../NonInstanceMapper.java | 20 ++++++++
.../NonPublicIterableMapper.java | 19 ++++++++
.../NonPublicMapper.java | 20 ++++++++
.../ap/test/defaultcomponentmodel/Source.java | 22 +++++++++
.../ap/test/defaultcomponentmodel/Target.java | 22 +++++++++
.../InstanceIterableMapperImpl.java | 34 ++++++++++++++
.../NonInstanceIterableMapperImpl.java | 35 ++++++++++++++
.../NonPublicIterableMapperImpl.java | 35 ++++++++++++++
12 files changed, 311 insertions(+)
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/DefaultComponentModelMapperTest.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapper.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceMapper.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapper.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceMapper.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapper.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicMapper.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Source.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Target.java
create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapperImpl.java
create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapperImpl.java
create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapperImpl.java
diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/DefaultComponentModelMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/DefaultComponentModelMapperTest.java
new file mode 100644
index 0000000000..b6b19ea88d
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/DefaultComponentModelMapperTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.defaultcomponentmodel;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mapstruct.ap.testutil.IssueKey;
+import org.mapstruct.ap.testutil.WithClasses;
+import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
+import org.mapstruct.ap.testutil.runner.GeneratedSource;
+
+/**
+ * @author Filip Hrisafov
+ */
+@IssueKey("2277")
+@RunWith(AnnotationProcessorTestRunner.class)
+@WithClasses({
+ Source.class,
+ Target.class,
+})
+public class DefaultComponentModelMapperTest {
+
+ @Rule
+ public final GeneratedSource generatedSource = new GeneratedSource();
+
+ @Test
+ @WithClasses({
+ InstanceIterableMapper.class,
+ InstanceMapper.class,
+ NonInstanceIterableMapper.class,
+ NonInstanceMapper.class,
+ NonPublicIterableMapper.class,
+ NonPublicMapper.class,
+ })
+ public void shouldGenerateCorrectMapperInstantiation() {
+ generatedSource.addComparisonToFixtureFor(
+ InstanceIterableMapper.class,
+ NonInstanceIterableMapper.class,
+ NonPublicIterableMapper.class
+ );
+ }
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapper.java
new file mode 100644
index 0000000000..b5b0506b62
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapper.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.defaultcomponentmodel;
+
+import java.util.List;
+
+import org.mapstruct.Mapper;
+
+/**
+ * @author Filip Hrisafov
+ */
+@Mapper(uses = InstanceMapper.class)
+public interface InstanceIterableMapper {
+
+ List map(List list);
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceMapper.java
new file mode 100644
index 0000000000..902ed551cd
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceMapper.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.defaultcomponentmodel;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * @author Filip Hrisafov
+ */
+@Mapper
+public interface InstanceMapper {
+
+ InstanceMapper INSTANCE = Mappers.getMapper( InstanceMapper.class );
+
+ Target map(Source source);
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapper.java
new file mode 100644
index 0000000000..6cdbe53006
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapper.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.defaultcomponentmodel;
+
+import java.util.List;
+
+import org.mapstruct.Mapper;
+
+/**
+ * @author Filip Hrisafov
+ */
+@Mapper(uses = NonInstanceMapper.class)
+public interface NonInstanceIterableMapper {
+
+ List map(List list);
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceMapper.java
new file mode 100644
index 0000000000..0d7f68392c
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceMapper.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.defaultcomponentmodel;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * @author Filip Hrisafov
+ */
+@Mapper
+public interface NonInstanceMapper {
+
+ NonInstanceMapper MAPPER = Mappers.getMapper( NonInstanceMapper.class );
+
+ Target map(Source source);
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapper.java
new file mode 100644
index 0000000000..20d6dbc1e7
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapper.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.defaultcomponentmodel;
+
+import java.util.List;
+
+import org.mapstruct.Mapper;
+
+/**
+ * @author Filip Hrisafov
+ */
+@Mapper(uses = NonPublicMapper.class)
+public interface NonPublicIterableMapper {
+
+ List map(List list);
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicMapper.java
new file mode 100644
index 0000000000..36f9b978f2
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicMapper.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.defaultcomponentmodel;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * @author Filip Hrisafov
+ */
+@Mapper
+public abstract class NonPublicMapper {
+
+ static final NonPublicMapper INSTANCE = Mappers.getMapper( NonPublicMapper.class );
+
+ public abstract Target map(Source source);
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Source.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Source.java
new file mode 100644
index 0000000000..a6aa152e20
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Source.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.defaultcomponentmodel;
+
+/**
+ * @author Filip Hrisafov
+ */
+public class Source {
+
+ private final String id;
+
+ public Source(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Target.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Target.java
new file mode 100644
index 0000000000..da7bfdbed0
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Target.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.defaultcomponentmodel;
+
+/**
+ * @author Filip Hrisafov
+ */
+public class Target {
+
+ private final String id;
+
+ public Target(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+}
diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapperImpl.java
new file mode 100644
index 0000000000..7dab330793
--- /dev/null
+++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapperImpl.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.defaultcomponentmodel;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.processing.Generated;
+
+@Generated(
+ value = "org.mapstruct.ap.MappingProcessor",
+ date = "2021-02-06T16:20:45+0100",
+ comments = "version: , compiler: javac, environment: Java 11.0.9.1 (AdoptOpenJDK)"
+)
+public class InstanceIterableMapperImpl implements InstanceIterableMapper {
+
+ private final InstanceMapper instanceMapper = InstanceMapper.INSTANCE;
+
+ @Override
+ public List map(List list) {
+ if ( list == null ) {
+ return null;
+ }
+
+ List list1 = new ArrayList( list.size() );
+ for ( Source source : list ) {
+ list1.add( instanceMapper.map( source ) );
+ }
+
+ return list1;
+ }
+}
diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapperImpl.java
new file mode 100644
index 0000000000..3854376bad
--- /dev/null
+++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapperImpl.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.defaultcomponentmodel;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.processing.Generated;
+import org.mapstruct.factory.Mappers;
+
+@Generated(
+ value = "org.mapstruct.ap.MappingProcessor",
+ date = "2021-02-06T16:20:45+0100",
+ comments = "version: , compiler: javac, environment: Java 11.0.9.1 (AdoptOpenJDK)"
+)
+public class NonInstanceIterableMapperImpl implements NonInstanceIterableMapper {
+
+ private final NonInstanceMapper nonInstanceMapper = Mappers.getMapper( NonInstanceMapper.class );
+
+ @Override
+ public List map(List list) {
+ if ( list == null ) {
+ return null;
+ }
+
+ List list1 = new ArrayList( list.size() );
+ for ( Source source : list ) {
+ list1.add( nonInstanceMapper.map( source ) );
+ }
+
+ return list1;
+ }
+}
diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapperImpl.java
new file mode 100644
index 0000000000..4cca04617a
--- /dev/null
+++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapperImpl.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.defaultcomponentmodel;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.processing.Generated;
+import org.mapstruct.factory.Mappers;
+
+@Generated(
+ value = "org.mapstruct.ap.MappingProcessor",
+ date = "2021-02-06T16:20:45+0100",
+ comments = "version: , compiler: javac, environment: Java 11.0.9.1 (AdoptOpenJDK)"
+)
+public class NonPublicIterableMapperImpl implements NonPublicIterableMapper {
+
+ private final NonPublicMapper nonPublicMapper = Mappers.getMapper( NonPublicMapper.class );
+
+ @Override
+ public List map(List list) {
+ if ( list == null ) {
+ return null;
+ }
+
+ List list1 = new ArrayList( list.size() );
+ for ( Source source : list ) {
+ list1.add( nonPublicMapper.map( source ) );
+ }
+
+ return list1;
+ }
+}
From 630a8da904d4669507fdf31f86ef96ac0deb1954 Mon Sep 17 00:00:00 2001
From: Filip Hrisafov
Date: Sat, 6 Feb 2021 16:44:07 +0100
Subject: [PATCH 012/471] Fix a typo in the Mapper#componentModel
---
core/src/main/java/org/mapstruct/Mapper.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java
index 5ed9eab17f..92d393f6c8 100644
--- a/core/src/main/java/org/mapstruct/Mapper.java
+++ b/core/src/main/java/org/mapstruct/Mapper.java
@@ -143,7 +143,7 @@
* {@code jsr330}: the generated mapper is annotated with {@code @javax.inject.Named} and
* {@code @Singleton}, and can be retrieved via {@code @Inject}
*
- * The method overrides an unmappedTargetPolicy set in a central configuration set
+ * The method overrides a componentModel set in a central configuration set
* by {@link #config() }
*
* @return The component model for the generated mapper.
From f4b62ded8910c0bc6d09fc677f887c3775ed1827 Mon Sep 17 00:00:00 2001
From: Filip Hrisafov
Date: Fri, 5 Feb 2021 23:01:41 +0100
Subject: [PATCH 013/471] #2352 Add source element type for Iterable mappings
When the Iterable type we are mapping is not generic
(i.e. it is a custom type extending an Iterable) then the source element type
which is included in the loop was not imported.
---
.../internal/model/IterableMappingMethod.java | 9 ++++
.../ap/test/bugs/_2352/Issue2352Test.java | 49 +++++++++++++++++++
.../ap/test/bugs/_2352/dto/TheDto.java | 22 +++++++++
.../ap/test/bugs/_2352/dto/TheModel.java | 22 +++++++++
.../ap/test/bugs/_2352/dto/TheModels.java | 15 ++++++
.../bugs/_2352/mapper/TheModelMapper.java | 19 +++++++
.../bugs/_2352/mapper/TheModelsMapper.java | 24 +++++++++
7 files changed, 160 insertions(+)
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/Issue2352Test.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheDto.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModel.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModels.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelMapper.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelsMapper.java
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java
index 5310fa382d..38ec44f1e1 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java
@@ -9,6 +9,7 @@
import java.util.Collection;
import java.util.List;
+import java.util.Set;
import org.mapstruct.ap.internal.model.assignment.LocalVarWrapper;
import org.mapstruct.ap.internal.model.assignment.SetterWrapper;
@@ -86,6 +87,14 @@ private IterableMappingMethod(Method method, Collection existingVariable
);
}
+ @Override
+ public Set getImportTypes() {
+ Set types = super.getImportTypes();
+
+ types.add( getSourceElementType() );
+ return types;
+ }
+
public Type getSourceElementType() {
Type sourceParameterType = getSourceParameter().getType();
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/Issue2352Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/Issue2352Test.java
new file mode 100644
index 0000000000..ebf6ac1e1c
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/Issue2352Test.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2352;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mapstruct.ap.test.bugs._2352.dto.TheDto;
+import org.mapstruct.ap.test.bugs._2352.dto.TheModel;
+import org.mapstruct.ap.test.bugs._2352.dto.TheModels;
+import org.mapstruct.ap.test.bugs._2352.mapper.TheModelMapper;
+import org.mapstruct.ap.test.bugs._2352.mapper.TheModelsMapper;
+import org.mapstruct.ap.testutil.IssueKey;
+import org.mapstruct.ap.testutil.WithClasses;
+import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * @author Filip Hrisafov
+ */
+@IssueKey("2352")
+@RunWith(AnnotationProcessorTestRunner.class)
+@WithClasses({
+ TheDto.class,
+ TheModel.class,
+ TheModels.class,
+ TheModelMapper.class,
+ TheModelsMapper.class,
+})
+public class Issue2352Test {
+
+ @Test
+ public void shouldGenerateValidCode() {
+ TheModels theModels = new TheModels();
+ theModels.add( new TheModel( "1" ) );
+ theModels.add( new TheModel( "2" ) );
+
+ List theDtos = TheModelsMapper.INSTANCE.convert( theModels );
+
+ assertThat( theDtos )
+ .extracting( TheDto::getId )
+ .containsExactly( "1", "2" );
+ }
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheDto.java
new file mode 100644
index 0000000000..a07c8bd093
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheDto.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2352.dto;
+
+/**
+ * @author Filip Hrisafov
+ */
+public class TheDto {
+
+ private String id;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModel.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModel.java
new file mode 100644
index 0000000000..fc7b1e89be
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModel.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2352.dto;
+
+/**
+ * @author Filip Hrisafov
+ */
+public class TheModel {
+
+ private final String id;
+
+ public TheModel(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModels.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModels.java
new file mode 100644
index 0000000000..37359ce779
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModels.java
@@ -0,0 +1,15 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2352.dto;
+
+import java.util.ArrayList;
+
+/**
+ * @author Filip Hrisafov
+ */
+public class TheModels extends ArrayList {
+
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelMapper.java
new file mode 100644
index 0000000000..2e9b5be478
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelMapper.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2352.mapper;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.ap.test.bugs._2352.dto.TheDto;
+import org.mapstruct.ap.test.bugs._2352.dto.TheModel;
+
+/**
+ * @author Filip Hrisafov
+ */
+@Mapper
+public interface TheModelMapper {
+
+ TheDto convert(TheModel theModel);
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelsMapper.java
new file mode 100644
index 0000000000..cf6c30409c
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelsMapper.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2352.mapper;
+
+import java.util.List;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.ap.test.bugs._2352.dto.TheDto;
+import org.mapstruct.ap.test.bugs._2352.dto.TheModels;
+import org.mapstruct.factory.Mappers;
+
+/**
+ * @author Filip Hrisafov
+ */
+@Mapper(uses = TheModelMapper.class)
+public interface TheModelsMapper {
+
+ TheModelsMapper INSTANCE = Mappers.getMapper( TheModelsMapper.class );
+
+ List convert(TheModels theModels);
+}
From 07f5189a722396c17e1df8a2debbaefb5a337e32 Mon Sep 17 00:00:00 2001
From: Filip Hrisafov
Date: Sat, 6 Feb 2021 10:26:08 +0100
Subject: [PATCH 014/471] #2347 Do not generate mapper implementation for
private mappers
Provide a compiler error message instead of generating code that will not compile
---
.../processor/MapperCreationProcessor.java | 12 +++++
.../mapstruct/ap/internal/util/Message.java | 1 +
.../ErroneousClassWithPrivateMapper.java | 51 +++++++++++++++++++
.../ap/test/bugs/_2347/Issue2347Test.java | 49 ++++++++++++++++++
4 files changed, 113 insertions(+)
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/ErroneousClassWithPrivateMapper.java
create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/Issue2347Test.java
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java
index ad6d84b9e9..c887140723 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java
@@ -15,6 +15,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
@@ -210,6 +211,17 @@ private Mapper getMapper(TypeElement element, MapperOptions mapperOptions, List<
mappingContext.getForgedMethodsUnderCreation().keySet() );
}
+ if ( element.getModifiers().contains( Modifier.PRIVATE ) ) {
+ // If the mapper element is private then we should report an error
+ // we can't generate an implementation for a private mapper
+ mappingContext.getMessager()
+ .printMessage( element,
+ Message.GENERAL_CANNOT_IMPLEMENT_PRIVATE_MAPPER,
+ element.getSimpleName().toString(),
+ element.getKind() == ElementKind.INTERFACE ? "interface" : "class"
+ );
+ }
+
return mapper;
}
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java
index d88791fda1..378395d4da 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java
@@ -115,6 +115,7 @@ public enum Message {
DECORATOR_NO_SUBTYPE( "Specified decorator type is no subtype of the annotated mapper type." ),
DECORATOR_CONSTRUCTOR( "Specified decorator type has no default constructor nor a constructor with a single parameter accepting the decorated mapper type." ),
+ GENERAL_CANNOT_IMPLEMENT_PRIVATE_MAPPER("Cannot create an implementation for mapper %s, because it is a private %s."),
GENERAL_NO_IMPLEMENTATION( "No implementation type is registered for return type %s." ),
GENERAL_ABSTRACT_RETURN_TYPE( "The return type %s is an abstract class or interface. Provide a non abstract / non interface result type or a factory method." ),
GENERAL_AMBIGUOUS_MAPPING_METHOD( "Ambiguous mapping methods found for mapping %s to %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ),
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/ErroneousClassWithPrivateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/ErroneousClassWithPrivateMapper.java
new file mode 100644
index 0000000000..c18620887e
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/ErroneousClassWithPrivateMapper.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2347;
+
+import org.mapstruct.Mapper;
+
+/**
+ * @author Filip Hrisafov
+ */
+public class ErroneousClassWithPrivateMapper {
+
+ public static class Target {
+ private final String id;
+
+ public Target(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+ }
+
+ public static class Source {
+
+ private final String id;
+
+ public Source(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+ }
+
+ @Mapper
+ private interface PrivateInterfaceMapper {
+
+ Target map(Source source);
+ }
+
+ @Mapper
+ private abstract class PrivateClassMapper {
+
+ public abstract Target map(Source source);
+ }
+}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/Issue2347Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/Issue2347Test.java
new file mode 100644
index 0000000000..f5e04fc776
--- /dev/null
+++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/Issue2347Test.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright MapStruct Authors.
+ *
+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
+ */
+package org.mapstruct.ap.test.bugs._2347;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mapstruct.ap.testutil.IssueKey;
+import org.mapstruct.ap.testutil.WithClasses;
+import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
+import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
+import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
+import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
+
+/**
+ * @author Filip Hrisafov
+ */
+@IssueKey("2347")
+@RunWith(AnnotationProcessorTestRunner.class)
+@WithClasses({
+ ErroneousClassWithPrivateMapper.class
+})
+public class Issue2347Test {
+
+ @ExpectedCompilationOutcome(value = CompilationResult.FAILED,
+ diagnostics = {
+ @Diagnostic(
+ type = ErroneousClassWithPrivateMapper.class,
+ kind = javax.tools.Diagnostic.Kind.ERROR,
+ line = 41,
+ message = "Cannot create an implementation for mapper PrivateInterfaceMapper," +
+ " because it is a private interface."
+ ),
+ @Diagnostic(
+ type = ErroneousClassWithPrivateMapper.class,
+ kind = javax.tools.Diagnostic.Kind.ERROR,
+ line = 47,
+ message = "Cannot create an implementation for mapper PrivateClassMapper," +
+ " because it is a private class."
+ )
+ }
+ )
+ @Test
+ public void shouldGenerateCompileErrorWhenMapperIsPrivate() {
+
+ }
+}
From 85af901ea7d7bc6cbdc52952211df76fc290f426 Mon Sep 17 00:00:00 2001
From: Filip Hrisafov
Date: Sat, 6 Feb 2021 09:05:40 +0100
Subject: [PATCH 015/471] #2350 Generate core string to enum mapping when
AnyRemaining or AnyUnmapped is not used
---
.../ap/internal/model/ValueMappingMethod.java | 9 +++------
.../string2enum/StringToEnumMappingTest.java | 16 +++++++++++++++-
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java
index c26dd5df6b..627a4b7288 100644
--- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java
+++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java
@@ -262,8 +262,8 @@ private List stringToEnumMapping(Method method, Type targetType )
List mappings = new ArrayList<>();
List unmappedSourceConstants = new ArrayList<>( targetType.getEnumConstants() );
boolean sourceErrorOccurred = !reportErrorIfMappedTargetEnumConstantsDontExist( method, targetType );
- boolean mandatoryMissing = !reportErrorIfAnyRemainingOrAnyUnMappedMissing( method );
- if ( sourceErrorOccurred || mandatoryMissing ) {
+ reportWarningIfAnyRemainingOrAnyUnMappedMissing( method );
+ if ( sourceErrorOccurred ) {
return mappings;
}
Set mappedSources = new LinkedHashSet<>();
@@ -344,17 +344,14 @@ private boolean reportErrorIfSourceEnumConstantsContainsAnyRemaining(Method meth
return !foundIncorrectMapping;
}
- private boolean reportErrorIfAnyRemainingOrAnyUnMappedMissing(Method method) {
- boolean foundIncorrectMapping = false;
+ private void reportWarningIfAnyRemainingOrAnyUnMappedMissing(Method method) {
if ( !( valueMappings.hasMapAnyUnmapped || valueMappings.hasMapAnyRemaining ) ) {
ctx.getMessager().printMessage(
method.getExecutable(),
Message.VALUEMAPPING_ANY_REMAINING_OR_UNMAPPED_MISSING
);
- foundIncorrectMapping = true;
}
- return !foundIncorrectMapping;
}
private boolean reportErrorIfMappedTargetEnumConstantsDontExist(Method method, Type targetType) {
diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java
index 7bf06ab860..fea8efac12 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java
@@ -16,6 +16,7 @@
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
@IssueKey( "1557" )
@WithClasses({ OrderType.class, OrderMapper.class })
@@ -53,7 +54,20 @@ public void testRemainingAndNull() {
"type String to an enum type." )
}
)
- public void shouldRaiseErrorWhenUsingAnyRemaining() {
+ public void shouldRaiseWarningWhenNotUsingAnyRemainingOrAnyUnmapped() {
+
+ assertThatThrownBy( () -> ErroneousOrderMapperUsingNoAnyRemainingAndNoAnyUnmapped.INSTANCE.map( "unknown" ) )
+ .isInstanceOf( IllegalArgumentException.class )
+ .hasMessage( "Unexpected enum constant: unknown" );
+
+ assertThat( ErroneousOrderMapperUsingNoAnyRemainingAndNoAnyUnmapped.INSTANCE.map( null ) )
+ .isEqualTo( OrderType.STANDARD );
+
+ assertThat( ErroneousOrderMapperUsingNoAnyRemainingAndNoAnyUnmapped.INSTANCE.map( "STANDARD" ) )
+ .isNull();
+
+ assertThat( ErroneousOrderMapperUsingNoAnyRemainingAndNoAnyUnmapped.INSTANCE.map( "RETAIL" ) )
+ .isEqualTo( OrderType.RETAIL );
}
}
From d5703d3ee8ecb8bd12ce80c6cd7a477119b2bfb8 Mon Sep 17 00:00:00 2001
From: Jeroen van Wilgenburg
Date: Mon, 1 Mar 2021 07:27:47 +0100
Subject: [PATCH 016/471] #2368 fix order of target parameter in documentation
---
core/src/main/java/org/mapstruct/Mapper.java | 2 +-
core/src/main/java/org/mapstruct/Mappings.java | 8 ++++----
.../main/java/org/mapstruct/ValueMapping.java | 6 +++---
.../main/java/org/mapstruct/ValueMappings.java | 8 ++++----
...er-11-reusing-mapping-configurations.asciidoc | 2 +-
.../chapter-3-defining-a-mapper.asciidoc | 16 ++++++++--------
.../asciidoc/chapter-8-mapping-values.asciidoc | 6 +++---
.../model/beanmapping/SourceReference.java | 2 +-
.../model/beanmapping/TargetReference.java | 2 +-
readme.md | 2 +-
10 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java
index 92d393f6c8..98022f1a6c 100644
--- a/core/src/main/java/org/mapstruct/Mapper.java
+++ b/core/src/main/java/org/mapstruct/Mapper.java
@@ -47,7 +47,7 @@
* uses = MarkMapper.class,
* injectionStrategy = InjectionStrategy.CONSTRUCTOR)
* public interface CarMapper {
- * @Mapping(source = "mark", target = "name")
+ * @Mapping(target = "name", source = "mark")
* CarDto convertMap(CarEntity carEntity);
* }
*
+ * NOTE: The value is only applicable to {@link ValueMapping#target()} and not to {@link ValueMapping#source()}.
+ */
+ public static final String THROW_EXCEPTION = "";
+
/**
* In an {@link EnumMapping} this represent the enum transformation strategy that adds a suffix to the source enum.
*
diff --git a/core/src/main/java/org/mapstruct/ValueMapping.java b/core/src/main/java/org/mapstruct/ValueMapping.java
index f8f2d3b18e..2d4a586366 100644
--- a/core/src/main/java/org/mapstruct/ValueMapping.java
+++ b/core/src/main/java/org/mapstruct/ValueMapping.java
@@ -23,7 +23,8 @@
*
*
*
- * public enum OrderType { RETAIL, B2B, EXTRA, STANDARD, NORMAL }
+ *
+ * public enum OrderType { RETAIL, B2B, C2C, EXTRA, STANDARD, NORMAL }
*
* public enum ExternalOrderType { RETAIL, B2B, SPECIAL, DEFAULT }
*
@@ -45,13 +46,12 @@
* +---------------------+----------------------------+
*
*
- * MapStruct will WARN on incomplete mappings. However, if for some reason no match is found an
- * {@link java.lang.IllegalStateException} will be thrown.
*
+ *
+ * MapStruct will WARN on incomplete mappings. However, if for some reason no match is found, an
+ * {@link java.lang.IllegalStateException} will be thrown. This compile-time error can be avoided by
+ * using {@link MappingConstants#THROW_EXCEPTION} for {@link ValueMapping#target()}. It will result an
+ * {@link java.lang.IllegalArgumentException} at runtime.
+ *