mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
parent
6b49c838eb
commit
2d3761051a
@ -10,8 +10,8 @@
|
|||||||
<!-- the annotation processor may not use the annotations or enums specified in org.mapstruct directly... -->
|
<!-- the annotation processor may not use the annotations or enums specified in org.mapstruct directly... -->
|
||||||
<disallow pkg="org.mapstruct" exact-match="true" />
|
<disallow pkg="org.mapstruct" exact-match="true" />
|
||||||
|
|
||||||
<subpackage name="internal.prism">
|
<subpackage name="internal.gem">
|
||||||
<!-- ... with exception to the package org.mapstruct.ap.internal.prism -->
|
<!-- ... with exception to the package org.mapstruct.ap.internal.gem -->
|
||||||
<allow pkg=".*" regex="true" />
|
<allow pkg=".*" regex="true" />
|
||||||
</subpackage>
|
</subpackage>
|
||||||
<subpackage name="test">
|
<subpackage name="test">
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<com.jolira.hickory.version>1.0.0</com.jolira.hickory.version>
|
<org.mapstruct.gem.version>1.0.0.Alpha1</org.mapstruct.gem.version>
|
||||||
<!-- We can't go to 3.0.0-M2 as it has a regression. See https://issues.apache.org/jira/browse/MENFORCER-306 -->
|
<!-- We can't go to 3.0.0-M2 as it has a regression. See https://issues.apache.org/jira/browse/MENFORCER-306 -->
|
||||||
<org.apache.maven.plugins.enforcer.version>3.0.0-M1</org.apache.maven.plugins.enforcer.version>
|
<org.apache.maven.plugins.enforcer.version>3.0.0-M1</org.apache.maven.plugins.enforcer.version>
|
||||||
<org.apache.maven.plugins.surefire.version>3.0.0-M3</org.apache.maven.plugins.surefire.version>
|
<org.apache.maven.plugins.surefire.version>3.0.0-M3</org.apache.maven.plugins.surefire.version>
|
||||||
@ -109,9 +109,14 @@
|
|||||||
<version>19.0</version>
|
<version>19.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jolira</groupId>
|
<groupId>org.mapstruct.tools.gem</groupId>
|
||||||
<artifactId>hickory</artifactId>
|
<artifactId>gem-api</artifactId>
|
||||||
<version>${com.jolira.hickory.version}</version>
|
<version>${org.mapstruct.gem.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct.tools.gem</groupId>
|
||||||
|
<artifactId>gem-processor</artifactId>
|
||||||
|
<version>${org.mapstruct.gem.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
@ -287,7 +292,7 @@
|
|||||||
specified as patterns within a source folder, so we can't exclude generated-sources
|
specified as patterns within a source folder, so we can't exclude generated-sources
|
||||||
altogether
|
altogether
|
||||||
-->
|
-->
|
||||||
<excludes>**/*Prism.java,*/itest/jaxb/xsd/*</excludes>
|
<excludes>**/*Gem.java,*/itest/jaxb/xsd/*</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -376,7 +381,7 @@
|
|||||||
<version>${org.apache.maven.plugins.javadoc.version}</version>
|
<version>${org.apache.maven.plugins.javadoc.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<quiet>true</quiet>
|
<quiet>true</quiet>
|
||||||
<excludePackageNames>org.mapstruct.ap.internal.prism;org.mapstruct.itest.jaxb.xsd.*</excludePackageNames>
|
<excludePackageNames>org.mapstruct.ap.internal.gem;org.mapstruct.itest.jaxb.xsd.*</excludePackageNames>
|
||||||
<source>8</source>
|
<source>8</source>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
@ -32,18 +32,9 @@
|
|||||||
<groupId>org.freemarker</groupId>
|
<groupId>org.freemarker</groupId>
|
||||||
<artifactId>freemarker</artifactId>
|
<artifactId>freemarker</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Compile-only; Using "provided" scope as there is no such scope in Maven;
|
|
||||||
these dependencies are not required at runtime, only for prism generation
|
|
||||||
and tests -->
|
|
||||||
<!-- Using optional as well due to IntelliJ picking up the dependency
|
|
||||||
and running the hickory processor in projects using the mapstruct-processor.
|
|
||||||
This happens only when the processor is defined in the maven-compiler annotationProcessorPaths -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jolira</groupId>
|
<groupId>org.mapstruct.tools.gem</groupId>
|
||||||
<artifactId>hickory</artifactId>
|
<artifactId>gem-api</artifactId>
|
||||||
<scope>provided</scope>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.groupId}</groupId>
|
<groupId>${project.groupId}</groupId>
|
||||||
@ -182,6 +173,12 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<minimizeJar>true</minimizeJar>
|
<minimizeJar>true</minimizeJar>
|
||||||
|
<artifactSet>
|
||||||
|
<includes>
|
||||||
|
<include>org.freemarker:*</include>
|
||||||
|
<include>org.mapstruct.tools.gem:gem-api</include>
|
||||||
|
</includes>
|
||||||
|
</artifactSet>
|
||||||
<filters>
|
<filters>
|
||||||
<filter>
|
<filter>
|
||||||
<artifact>org.freemarker:freemarker</artifact>
|
<artifact>org.freemarker:freemarker</artifact>
|
||||||
@ -189,12 +186,24 @@
|
|||||||
<exclude>META-INF/*.*</exclude>
|
<exclude>META-INF/*.*</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
</filter>
|
</filter>
|
||||||
|
<filter>
|
||||||
|
<artifact>org.mapstruct.tools.gem:gem-api</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/*.*</exclude>
|
||||||
|
<exclude>**/GemDefinition.class</exclude>
|
||||||
|
<exclude>**/GemDefinitions.class</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
</filters>
|
</filters>
|
||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>freemarker</pattern>
|
<pattern>freemarker</pattern>
|
||||||
<shadedPattern>org.mapstruct.ap.shaded.freemarker</shadedPattern>
|
<shadedPattern>org.mapstruct.ap.shaded.freemarker</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.mapstruct.tools.gem</pattern>
|
||||||
|
<shadedPattern>org.mapstruct.ap.shaded.org.mapstruct.tools.gem</shadedPattern>
|
||||||
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
@ -227,9 +236,14 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<annotationProcessors>
|
<annotationProcessorPaths>
|
||||||
<annotationProcessor>net.java.dev.hickory.prism.internal.PrismGenerator</annotationProcessor>
|
<path>
|
||||||
</annotationProcessors>
|
<groupId>org.mapstruct.tools.gem</groupId>
|
||||||
|
<artifactId>gem-processor</artifactId>
|
||||||
|
<version>${org.mapstruct.gem.version}</version>
|
||||||
|
</path>
|
||||||
|
<!-- other annotation processors -->
|
||||||
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -34,8 +34,8 @@ import javax.tools.Diagnostic.Kind;
|
|||||||
|
|
||||||
import org.mapstruct.ap.internal.model.Mapper;
|
import org.mapstruct.ap.internal.model.Mapper;
|
||||||
import org.mapstruct.ap.internal.option.Options;
|
import org.mapstruct.ap.internal.option.Options;
|
||||||
import org.mapstruct.ap.internal.prism.MapperPrism;
|
import org.mapstruct.ap.internal.gem.MapperGem;
|
||||||
import org.mapstruct.ap.internal.prism.ReportingPolicyPrism;
|
import org.mapstruct.ap.internal.gem.ReportingPolicyGem;
|
||||||
import org.mapstruct.ap.internal.processor.DefaultModelElementProcessorContext;
|
import org.mapstruct.ap.internal.processor.DefaultModelElementProcessorContext;
|
||||||
import org.mapstruct.ap.internal.processor.ModelElementProcessor;
|
import org.mapstruct.ap.internal.processor.ModelElementProcessor;
|
||||||
import org.mapstruct.ap.internal.processor.ModelElementProcessor.ProcessorContext;
|
import org.mapstruct.ap.internal.processor.ModelElementProcessor.ProcessorContext;
|
||||||
@ -66,8 +66,8 @@ import static javax.lang.model.element.ElementKind.CLASS;
|
|||||||
* <li>if no error occurred, write out the model into Java source files</li>
|
* <li>if no error occurred, write out the model into Java source files</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* <p>
|
* <p>
|
||||||
* For reading annotation attributes, prisms as generated with help of the <a
|
* For reading annotation attributes, gems as generated with help of the <a
|
||||||
* href="https://java.net/projects/hickory">Hickory</a> tool are used. These prisms allow a comfortable access to
|
* href="https://java.net/projects/hickory">Hickory</a> tool are used. These gems allow a comfortable access to
|
||||||
* annotations and their attributes without depending on their class objects.
|
* annotations and their attributes without depending on their class objects.
|
||||||
* <p>
|
* <p>
|
||||||
* The creation of Java source files is done using the <a href="http://freemarker.org/"> FreeMarker</a> template engine.
|
* The creation of Java source files is done using the <a href="http://freemarker.org/"> FreeMarker</a> template engine.
|
||||||
@ -137,7 +137,7 @@ public class MappingProcessor extends AbstractProcessor {
|
|||||||
return new Options(
|
return new Options(
|
||||||
Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP ) ),
|
Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP ) ),
|
||||||
Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ) ),
|
Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ) ),
|
||||||
unmappedTargetPolicy != null ? ReportingPolicyPrism.valueOf( unmappedTargetPolicy.toUpperCase() ) : null,
|
unmappedTargetPolicy != null ? ReportingPolicyGem.valueOf( unmappedTargetPolicy.toUpperCase() ) : null,
|
||||||
processingEnv.getOptions().get( DEFAULT_COMPONENT_MODEL ),
|
processingEnv.getOptions().get( DEFAULT_COMPONENT_MODEL ),
|
||||||
processingEnv.getOptions().get( DEFAULT_INJECTION_STRATEGY ),
|
processingEnv.getOptions().get( DEFAULT_INJECTION_STRATEGY ),
|
||||||
Boolean.valueOf( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ),
|
Boolean.valueOf( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ),
|
||||||
@ -236,7 +236,7 @@ public class MappingProcessor extends AbstractProcessor {
|
|||||||
|
|
||||||
// on some JDKs, RoundEnvironment.getElementsAnnotatedWith( ... ) returns types with
|
// on some JDKs, RoundEnvironment.getElementsAnnotatedWith( ... ) returns types with
|
||||||
// annotations unknown to the compiler, even though they are not declared Mappers
|
// annotations unknown to the compiler, even though they are not declared Mappers
|
||||||
if ( mapperTypeElement != null && MapperPrism.getInstanceOn( mapperTypeElement ) != null ) {
|
if ( mapperTypeElement != null && MapperGem.instanceOn( mapperTypeElement ) != null ) {
|
||||||
mapperTypes.add( mapperTypeElement );
|
mapperTypes.add( mapperTypeElement );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
*
|
*
|
||||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.prism;
|
package org.mapstruct.ap.internal.gem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prism for the enum {@link org.mapstruct.CollectionMappingStrategy}
|
* Gem for the enum {@link org.mapstruct.CollectionMappingStrategy}
|
||||||
*
|
*
|
||||||
* @author Andreas Gudian
|
* @author Andreas Gudian
|
||||||
*/
|
*/
|
||||||
public enum CollectionMappingStrategyPrism {
|
public enum CollectionMappingStrategyGem {
|
||||||
|
|
||||||
ACCESSOR_ONLY,
|
ACCESSOR_ONLY,
|
||||||
SETTER_PREFERRED,
|
SETTER_PREFERRED,
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.internal.gem;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElementDecl;
|
||||||
|
import javax.xml.bind.annotation.XmlElementRef;
|
||||||
|
|
||||||
|
import org.mapstruct.AfterMapping;
|
||||||
|
import org.mapstruct.BeanMapping;
|
||||||
|
import org.mapstruct.BeforeMapping;
|
||||||
|
import org.mapstruct.Builder;
|
||||||
|
import org.mapstruct.Context;
|
||||||
|
import org.mapstruct.DecoratedWith;
|
||||||
|
import org.mapstruct.InheritConfiguration;
|
||||||
|
import org.mapstruct.InheritInverseConfiguration;
|
||||||
|
import org.mapstruct.IterableMapping;
|
||||||
|
import org.mapstruct.MapMapping;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.MapperConfig;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
import org.mapstruct.MappingTarget;
|
||||||
|
import org.mapstruct.Mappings;
|
||||||
|
import org.mapstruct.Named;
|
||||||
|
import org.mapstruct.ObjectFactory;
|
||||||
|
import org.mapstruct.Qualifier;
|
||||||
|
import org.mapstruct.TargetType;
|
||||||
|
import org.mapstruct.ValueMapping;
|
||||||
|
import org.mapstruct.ValueMappings;
|
||||||
|
import org.mapstruct.tools.gem.GemDefinition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers the generation of ge types using <a href="https://java.net/projects/hickory">Hickory</a>.
|
||||||
|
*
|
||||||
|
* @author Gunnar Morling
|
||||||
|
*/
|
||||||
|
@GemDefinition(Mapper.class)
|
||||||
|
@GemDefinition(Mapping.class)
|
||||||
|
@GemDefinition(Mappings.class)
|
||||||
|
@GemDefinition(IterableMapping.class)
|
||||||
|
@GemDefinition(BeanMapping.class)
|
||||||
|
@GemDefinition(MapMapping.class)
|
||||||
|
@GemDefinition(TargetType.class)
|
||||||
|
@GemDefinition(MappingTarget.class)
|
||||||
|
@GemDefinition(DecoratedWith.class)
|
||||||
|
@GemDefinition(MapperConfig.class)
|
||||||
|
@GemDefinition(InheritConfiguration.class)
|
||||||
|
@GemDefinition(InheritInverseConfiguration.class)
|
||||||
|
@GemDefinition(Qualifier.class)
|
||||||
|
@GemDefinition(Named.class)
|
||||||
|
@GemDefinition(ObjectFactory.class)
|
||||||
|
@GemDefinition(AfterMapping.class)
|
||||||
|
@GemDefinition(BeforeMapping.class)
|
||||||
|
@GemDefinition(ValueMapping.class)
|
||||||
|
@GemDefinition(ValueMappings.class)
|
||||||
|
@GemDefinition(Context.class)
|
||||||
|
@GemDefinition(Builder.class)
|
||||||
|
|
||||||
|
// external types
|
||||||
|
@GemDefinition(XmlElementDecl.class)
|
||||||
|
@GemDefinition(XmlElementRef.class)
|
||||||
|
public class GemGenerator {
|
||||||
|
}
|
@ -3,14 +3,14 @@
|
|||||||
*
|
*
|
||||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.prism;
|
package org.mapstruct.ap.internal.gem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prism for the enum {@link org.mapstruct.InjectionStrategy}.
|
* Gem for the enum {@link org.mapstruct.InjectionStrategy}.
|
||||||
*
|
*
|
||||||
* @author Kevin Grüneberg
|
* @author Kevin Grüneberg
|
||||||
*/
|
*/
|
||||||
public enum InjectionStrategyPrism {
|
public enum InjectionStrategyGem {
|
||||||
|
|
||||||
FIELD,
|
FIELD,
|
||||||
CONSTRUCTOR;
|
CONSTRUCTOR;
|
@ -3,16 +3,16 @@
|
|||||||
*
|
*
|
||||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.prism;
|
package org.mapstruct.ap.internal.gem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prism for the enum {@link org.mapstruct.MappingConstants}
|
* Gem for the enum {@link org.mapstruct.MappingConstants}
|
||||||
*
|
*
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public final class MappingConstantsPrism {
|
public final class MappingConstantsGem {
|
||||||
|
|
||||||
private MappingConstantsPrism() {
|
private MappingConstantsGem() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String NULL = "<NULL>";
|
public static final String NULL = "<NULL>";
|
@ -3,15 +3,15 @@
|
|||||||
*
|
*
|
||||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.prism;
|
package org.mapstruct.ap.internal.gem;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prism for the enum {@link org.mapstruct.MappingInheritanceStrategy}
|
* Gem for the enum {@link org.mapstruct.MappingInheritanceStrategy}
|
||||||
*
|
*
|
||||||
* @author Andreas Gudian
|
* @author Andreas Gudian
|
||||||
*/
|
*/
|
||||||
public enum MappingInheritanceStrategyPrism {
|
public enum MappingInheritanceStrategyGem {
|
||||||
|
|
||||||
EXPLICIT( false, false, false ),
|
EXPLICIT( false, false, false ),
|
||||||
AUTO_INHERIT_FROM_CONFIG( true, true, false ),
|
AUTO_INHERIT_FROM_CONFIG( true, true, false ),
|
||||||
@ -22,7 +22,7 @@ public enum MappingInheritanceStrategyPrism {
|
|||||||
private final boolean applyForward;
|
private final boolean applyForward;
|
||||||
private final boolean applyReverse;
|
private final boolean applyReverse;
|
||||||
|
|
||||||
MappingInheritanceStrategyPrism(boolean isAutoInherit, boolean applyForward, boolean applyReverse) {
|
MappingInheritanceStrategyGem(boolean isAutoInherit, boolean applyForward, boolean applyReverse) {
|
||||||
this.autoInherit = isAutoInherit;
|
this.autoInherit = isAutoInherit;
|
||||||
this.applyForward = applyForward;
|
this.applyForward = applyForward;
|
||||||
this.applyReverse = applyReverse;
|
this.applyReverse = applyReverse;
|
@ -3,15 +3,15 @@
|
|||||||
*
|
*
|
||||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.prism;
|
package org.mapstruct.ap.internal.gem;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prism for the enum {@link org.mapstruct.NullValueCheckStrategy}
|
* Gem for the enum {@link org.mapstruct.NullValueCheckStrategy}
|
||||||
*
|
*
|
||||||
* @author Sean Huang
|
* @author Sean Huang
|
||||||
*/
|
*/
|
||||||
public enum NullValueCheckStrategyPrism {
|
public enum NullValueCheckStrategyGem {
|
||||||
|
|
||||||
ON_IMPLICIT_CONVERSION,
|
ON_IMPLICIT_CONVERSION,
|
||||||
ALWAYS;
|
ALWAYS;
|
@ -3,21 +3,21 @@
|
|||||||
*
|
*
|
||||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.prism;
|
package org.mapstruct.ap.internal.gem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prism for the enum {@link org.mapstruct.NullValueMappingStrategy}
|
* Gem for the enum {@link org.mapstruct.NullValueMappingStrategy}
|
||||||
*
|
*
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public enum NullValueMappingStrategyPrism {
|
public enum NullValueMappingStrategyGem {
|
||||||
|
|
||||||
RETURN_NULL( false ),
|
RETURN_NULL( false ),
|
||||||
RETURN_DEFAULT( true );
|
RETURN_DEFAULT( true );
|
||||||
|
|
||||||
private final boolean returnDefault;
|
private final boolean returnDefault;
|
||||||
|
|
||||||
NullValueMappingStrategyPrism(boolean returnDefault) {
|
NullValueMappingStrategyGem(boolean returnDefault) {
|
||||||
this.returnDefault = returnDefault;
|
this.returnDefault = returnDefault;
|
||||||
}
|
}
|
||||||
|
|
@ -3,15 +3,15 @@
|
|||||||
*
|
*
|
||||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.prism;
|
package org.mapstruct.ap.internal.gem;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prism for the enum {@link org.mapstruct.NullValuePropertyMappingStrategy}
|
* Gem for the enum {@link org.mapstruct.NullValuePropertyMappingStrategy}
|
||||||
*
|
*
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public enum NullValuePropertyMappingStrategyPrism {
|
public enum NullValuePropertyMappingStrategyGem {
|
||||||
|
|
||||||
SET_TO_NULL,
|
SET_TO_NULL,
|
||||||
SET_TO_DEFAULT,
|
SET_TO_DEFAULT,
|
@ -3,17 +3,17 @@
|
|||||||
*
|
*
|
||||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.prism;
|
package org.mapstruct.ap.internal.gem;
|
||||||
|
|
||||||
import javax.tools.Diagnostic;
|
import javax.tools.Diagnostic;
|
||||||
import javax.tools.Diagnostic.Kind;
|
import javax.tools.Diagnostic.Kind;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prism for the enum {@link org.mapstruct.ReportingPolicy}.
|
* Gem for the enum {@link org.mapstruct.ReportingPolicy}.
|
||||||
*
|
*
|
||||||
* @author Gunnar Morling
|
* @author Gunnar Morling
|
||||||
*/
|
*/
|
||||||
public enum ReportingPolicyPrism {
|
public enum ReportingPolicyGem {
|
||||||
|
|
||||||
IGNORE( null, false, false ),
|
IGNORE( null, false, false ),
|
||||||
WARN( Kind.WARNING, true, false ),
|
WARN( Kind.WARNING, true, false ),
|
||||||
@ -23,7 +23,7 @@ public enum ReportingPolicyPrism {
|
|||||||
private final boolean requiresReport;
|
private final boolean requiresReport;
|
||||||
private final boolean failsBuild;
|
private final boolean failsBuild;
|
||||||
|
|
||||||
ReportingPolicyPrism(Diagnostic.Kind diagnosticKind, boolean requiresReport, boolean failsBuild) {
|
ReportingPolicyGem(Diagnostic.Kind diagnosticKind, boolean requiresReport, boolean failsBuild) {
|
||||||
this.requiresReport = requiresReport;
|
this.requiresReport = requiresReport;
|
||||||
this.diagnosticKind = diagnosticKind;
|
this.diagnosticKind = diagnosticKind;
|
||||||
this.failsBuild = failsBuild;
|
this.failsBuild = failsBuild;
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* This package contains the generated prism types for accessing the MapStruct annotations in a comfortable way.
|
* This package contains the generated gem types for accessing the MapStruct annotations in a comfortable way.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.prism;
|
package org.mapstruct.ap.internal.gem;
|
@ -8,7 +8,7 @@ package org.mapstruct.ap.internal.model;
|
|||||||
import org.mapstruct.ap.internal.model.common.Assignment;
|
import org.mapstruct.ap.internal.model.common.Assignment;
|
||||||
import org.mapstruct.ap.internal.model.common.SourceRHS;
|
import org.mapstruct.ap.internal.model.common.SourceRHS;
|
||||||
import org.mapstruct.ap.internal.model.common.Type;
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
import org.mapstruct.ap.internal.prism.BuilderPrism;
|
import org.mapstruct.ap.internal.gem.BuilderGem;
|
||||||
import org.mapstruct.ap.internal.util.Strings;
|
import org.mapstruct.ap.internal.util.Strings;
|
||||||
|
|
||||||
import static org.mapstruct.ap.internal.model.ForgedMethod.forElementMapping;
|
import static org.mapstruct.ap.internal.model.ForgedMethod.forElementMapping;
|
||||||
@ -54,11 +54,11 @@ public abstract class AbstractMappingMethodBuilder<B extends AbstractMappingMeth
|
|||||||
sourceRHS.getSourceErrorMessagePart() );
|
sourceRHS.getSourceErrorMessagePart() );
|
||||||
|
|
||||||
ForgedMethod forgedMethod = forElementMapping( name, sourceType, targetType, method, forgedHistory, true );
|
ForgedMethod forgedMethod = forElementMapping( name, sourceType, targetType, method, forgedHistory, true );
|
||||||
BuilderPrism builderPrism = method.getOptions().getBeanMapping().getBuilderPrism();
|
BuilderGem builder = method.getOptions().getBeanMapping().getBuilder();
|
||||||
|
|
||||||
return createForgedAssignment(
|
return createForgedAssignment(
|
||||||
sourceRHS,
|
sourceRHS,
|
||||||
ctx.getTypeFactory().builderTypeFor( targetType, builderPrism ),
|
ctx.getTypeFactory().builderTypeFor( targetType, builder ),
|
||||||
forgedMethod
|
forgedMethod
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,8 @@ import org.mapstruct.ap.internal.model.source.MappingOptions;
|
|||||||
import org.mapstruct.ap.internal.model.source.Method;
|
import org.mapstruct.ap.internal.model.source.Method;
|
||||||
import org.mapstruct.ap.internal.model.source.SelectionParameters;
|
import org.mapstruct.ap.internal.model.source.SelectionParameters;
|
||||||
import org.mapstruct.ap.internal.model.source.SourceMethod;
|
import org.mapstruct.ap.internal.model.source.SourceMethod;
|
||||||
import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.ReportingPolicyPrism;
|
import org.mapstruct.ap.internal.gem.ReportingPolicyGem;
|
||||||
import org.mapstruct.ap.internal.util.Message;
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
import org.mapstruct.ap.internal.util.Strings;
|
import org.mapstruct.ap.internal.util.Strings;
|
||||||
import org.mapstruct.ap.internal.util.accessor.Accessor;
|
import org.mapstruct.ap.internal.util.accessor.Accessor;
|
||||||
@ -158,7 +158,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
|||||||
/* the type that needs to be used in the mapping process as target */
|
/* the type that needs to be used in the mapping process as target */
|
||||||
Type resultTypeToMap = returnTypeToConstruct == null ? method.getResultType() : returnTypeToConstruct;
|
Type resultTypeToMap = returnTypeToConstruct == null ? method.getResultType() : returnTypeToConstruct;
|
||||||
|
|
||||||
CollectionMappingStrategyPrism cms = this.method.getOptions().getMapper().getCollectionMappingStrategy();
|
CollectionMappingStrategyGem cms = this.method.getOptions().getMapper().getCollectionMappingStrategy();
|
||||||
|
|
||||||
// determine accessors
|
// determine accessors
|
||||||
Map<String, Accessor> accessors = resultTypeToMap.getPropertyWriteAccessors( cms );
|
Map<String, Accessor> accessors = resultTypeToMap.getPropertyWriteAccessors( cms );
|
||||||
@ -823,9 +823,9 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReportingPolicyPrism getUnmappedTargetPolicy() {
|
private ReportingPolicyGem getUnmappedTargetPolicy() {
|
||||||
if ( mappingReferences.isForForgedMethods() ) {
|
if ( mappingReferences.isForForgedMethods() ) {
|
||||||
return ReportingPolicyPrism.IGNORE;
|
return ReportingPolicyGem.IGNORE;
|
||||||
}
|
}
|
||||||
return method.getOptions().getMapper().unmappedTargetPolicy();
|
return method.getOptions().getMapper().unmappedTargetPolicy();
|
||||||
}
|
}
|
||||||
@ -833,7 +833,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
|||||||
private void reportErrorForUnmappedTargetPropertiesIfRequired() {
|
private void reportErrorForUnmappedTargetPropertiesIfRequired() {
|
||||||
|
|
||||||
// fetch settings from element to implement
|
// fetch settings from element to implement
|
||||||
ReportingPolicyPrism unmappedTargetPolicy = getUnmappedTargetPolicy();
|
ReportingPolicyGem unmappedTargetPolicy = getUnmappedTargetPolicy();
|
||||||
|
|
||||||
if ( method instanceof ForgedMethod && targetProperties.isEmpty() ) {
|
if ( method instanceof ForgedMethod && targetProperties.isEmpty() ) {
|
||||||
//TODO until we solve 1140 we report this error when the target properties are empty
|
//TODO until we solve 1140 we report this error when the target properties are empty
|
||||||
@ -904,15 +904,15 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReportingPolicyPrism getUnmappedSourcePolicy() {
|
private ReportingPolicyGem getUnmappedSourcePolicy() {
|
||||||
if ( mappingReferences.isForForgedMethods() ) {
|
if ( mappingReferences.isForForgedMethods() ) {
|
||||||
return ReportingPolicyPrism.IGNORE;
|
return ReportingPolicyGem.IGNORE;
|
||||||
}
|
}
|
||||||
return method.getOptions().getMapper().unmappedSourcePolicy();
|
return method.getOptions().getMapper().unmappedSourcePolicy();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reportErrorForUnmappedSourcePropertiesIfRequired() {
|
private void reportErrorForUnmappedSourcePropertiesIfRequired() {
|
||||||
ReportingPolicyPrism unmappedSourcePolicy = getUnmappedSourcePolicy();
|
ReportingPolicyGem unmappedSourcePolicy = getUnmappedSourcePolicy();
|
||||||
|
|
||||||
if ( !unprocessedSourceProperties.isEmpty() && unmappedSourcePolicy.requiresReport() ) {
|
if ( !unprocessedSourceProperties.isEmpty() && unmappedSourcePolicy.requiresReport() ) {
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import javax.lang.model.element.ExecutableElement;
|
|||||||
|
|
||||||
import org.mapstruct.ap.internal.model.common.BuilderType;
|
import org.mapstruct.ap.internal.model.common.BuilderType;
|
||||||
import org.mapstruct.ap.internal.model.source.Method;
|
import org.mapstruct.ap.internal.model.source.Method;
|
||||||
import org.mapstruct.ap.internal.prism.BuilderPrism;
|
import org.mapstruct.ap.internal.gem.BuilderGem;
|
||||||
import org.mapstruct.ap.internal.util.Message;
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
import org.mapstruct.ap.internal.util.Strings;
|
import org.mapstruct.ap.internal.util.Strings;
|
||||||
|
|
||||||
@ -34,14 +34,14 @@ public class BuilderFinisherMethodResolver {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
BuilderPrism builderMapping = method.getOptions().getBeanMapping().getBuilderPrism();
|
BuilderGem builder = method.getOptions().getBeanMapping().getBuilder();
|
||||||
if ( builderMapping == null && buildMethods.size() == 1 ) {
|
if ( builder == null && buildMethods.size() == 1 ) {
|
||||||
return MethodReference.forMethodCall( first( buildMethods ).getSimpleName().toString() );
|
return MethodReference.forMethodCall( first( buildMethods ).getSimpleName().toString() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String buildMethodPattern = DEFAULT_BUILD_METHOD_NAME;
|
String buildMethodPattern = DEFAULT_BUILD_METHOD_NAME;
|
||||||
if ( builderMapping != null ) {
|
if ( builder != null ) {
|
||||||
buildMethodPattern = builderMapping.buildMethod();
|
buildMethodPattern = builder.buildMethod().get();
|
||||||
}
|
}
|
||||||
for ( ExecutableElement buildMethod : buildMethods ) {
|
for ( ExecutableElement buildMethod : buildMethods ) {
|
||||||
String methodName = buildMethod.getSimpleName().toString();
|
String methodName = buildMethod.getSimpleName().toString();
|
||||||
@ -50,7 +50,7 @@ public class BuilderFinisherMethodResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( builderMapping == null ) {
|
if ( builder == null ) {
|
||||||
ctx.getMessager().printMessage(
|
ctx.getMessager().printMessage(
|
||||||
method.getExecutable(),
|
method.getExecutable(),
|
||||||
Message.BUILDER_NO_BUILD_METHOD_FOUND_DEFAULT,
|
Message.BUILDER_NO_BUILD_METHOD_FOUND_DEFAULT,
|
||||||
@ -63,7 +63,7 @@ public class BuilderFinisherMethodResolver {
|
|||||||
else {
|
else {
|
||||||
ctx.getMessager().printMessage(
|
ctx.getMessager().printMessage(
|
||||||
method.getExecutable(),
|
method.getExecutable(),
|
||||||
builderMapping.mirror,
|
builder.mirror(),
|
||||||
Message.BUILDER_NO_BUILD_METHOD_FOUND,
|
Message.BUILDER_NO_BUILD_METHOD_FOUND,
|
||||||
buildMethodPattern,
|
buildMethodPattern,
|
||||||
builderType.getBuilder(),
|
builderType.getBuilder(),
|
||||||
|
@ -15,15 +15,15 @@ import org.mapstruct.ap.internal.model.common.SourceRHS;
|
|||||||
import org.mapstruct.ap.internal.model.common.Type;
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
import org.mapstruct.ap.internal.model.source.Method;
|
import org.mapstruct.ap.internal.model.source.Method;
|
||||||
import org.mapstruct.ap.internal.model.source.SelectionParameters;
|
import org.mapstruct.ap.internal.model.source.SelectionParameters;
|
||||||
import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.util.Message;
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
import org.mapstruct.ap.internal.util.accessor.Accessor;
|
import org.mapstruct.ap.internal.util.accessor.Accessor;
|
||||||
import org.mapstruct.ap.internal.util.accessor.AccessorType;
|
import org.mapstruct.ap.internal.util.accessor.AccessorType;
|
||||||
|
|
||||||
import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT;
|
import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT;
|
||||||
import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_NULL;
|
import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A builder that is used for creating an assignment to a collection.
|
* A builder that is used for creating an assignment to a collection.
|
||||||
@ -61,8 +61,8 @@ public class CollectionAssignmentBuilder {
|
|||||||
private AccessorType targetAccessorType;
|
private AccessorType targetAccessorType;
|
||||||
private Assignment assignment;
|
private Assignment assignment;
|
||||||
private SourceRHS sourceRHS;
|
private SourceRHS sourceRHS;
|
||||||
private NullValueCheckStrategyPrism nvcs;
|
private NullValueCheckStrategyGem nvcs;
|
||||||
private NullValuePropertyMappingStrategyPrism nvpms;
|
private NullValuePropertyMappingStrategyGem nvpms;
|
||||||
|
|
||||||
public CollectionAssignmentBuilder mappingBuilderContext(MappingBuilderContext ctx) {
|
public CollectionAssignmentBuilder mappingBuilderContext(MappingBuilderContext ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
@ -114,12 +114,12 @@ public class CollectionAssignmentBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CollectionAssignmentBuilder nullValueCheckStrategy( NullValueCheckStrategyPrism nvcs ) {
|
public CollectionAssignmentBuilder nullValueCheckStrategy( NullValueCheckStrategyGem nvcs ) {
|
||||||
this.nvcs = nvcs;
|
this.nvcs = nvcs;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CollectionAssignmentBuilder nullValuePropertyMappingStrategy( NullValuePropertyMappingStrategyPrism nvpms ) {
|
public CollectionAssignmentBuilder nullValuePropertyMappingStrategy( NullValuePropertyMappingStrategyGem nvpms ) {
|
||||||
this.nvpms = nvpms;
|
this.nvpms = nvpms;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -127,8 +127,8 @@ public class CollectionAssignmentBuilder {
|
|||||||
public Assignment build() {
|
public Assignment build() {
|
||||||
Assignment result = assignment;
|
Assignment result = assignment;
|
||||||
|
|
||||||
CollectionMappingStrategyPrism cms = method.getOptions().getMapper().getCollectionMappingStrategy();
|
CollectionMappingStrategyGem cms = method.getOptions().getMapper().getCollectionMappingStrategy();
|
||||||
boolean targetImmutable = cms == CollectionMappingStrategyPrism.TARGET_IMMUTABLE || targetReadAccessor == null;
|
boolean targetImmutable = cms == CollectionMappingStrategyGem.TARGET_IMMUTABLE || targetReadAccessor == null;
|
||||||
|
|
||||||
if ( targetAccessorType == AccessorType.SETTER || targetAccessorType == AccessorType.FIELD ) {
|
if ( targetAccessorType == AccessorType.SETTER || targetAccessorType == AccessorType.FIELD ) {
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ public class CollectionAssignmentBuilder {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if ( result.getType() == Assignment.AssignmentType.DIRECT ||
|
else if ( result.getType() == Assignment.AssignmentType.DIRECT ||
|
||||||
nvcs == NullValueCheckStrategyPrism.ALWAYS ) {
|
nvcs == NullValueCheckStrategyGem.ALWAYS ) {
|
||||||
|
|
||||||
result = new SetterWrapperForCollectionsAndMapsWithNullCheck(
|
result = new SetterWrapperForCollectionsAndMapsWithNullCheck(
|
||||||
result,
|
result,
|
||||||
|
@ -8,7 +8,6 @@ package org.mapstruct.ap.internal.model;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
import javax.lang.model.element.ElementKind;
|
import javax.lang.model.element.ElementKind;
|
||||||
import javax.lang.model.element.TypeElement;
|
import javax.lang.model.element.TypeElement;
|
||||||
|
|
||||||
@ -16,7 +15,7 @@ import org.mapstruct.ap.internal.model.common.Accessibility;
|
|||||||
import org.mapstruct.ap.internal.model.common.Type;
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
||||||
import org.mapstruct.ap.internal.option.Options;
|
import org.mapstruct.ap.internal.option.Options;
|
||||||
import org.mapstruct.ap.internal.prism.DecoratedWithPrism;
|
import org.mapstruct.ap.internal.gem.DecoratedWithGem;
|
||||||
import org.mapstruct.ap.internal.version.VersionInformation;
|
import org.mapstruct.ap.internal.version.VersionInformation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +28,7 @@ public class Decorator extends GeneratedType {
|
|||||||
public static class Builder extends GeneratedTypeBuilder<Builder> {
|
public static class Builder extends GeneratedTypeBuilder<Builder> {
|
||||||
|
|
||||||
private TypeElement mapperElement;
|
private TypeElement mapperElement;
|
||||||
private DecoratedWithPrism decoratorPrism;
|
private DecoratedWithGem decorator;
|
||||||
|
|
||||||
private boolean hasDelegateConstructor;
|
private boolean hasDelegateConstructor;
|
||||||
private String implName;
|
private String implName;
|
||||||
@ -44,8 +43,8 @@ public class Decorator extends GeneratedType {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder decoratorPrism(DecoratedWithPrism decoratorPrism) {
|
public Builder decoratedWith(DecoratedWithGem decoratedGem) {
|
||||||
this.decoratorPrism = decoratorPrism;
|
this.decorator = decoratedGem;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +67,7 @@ public class Decorator extends GeneratedType {
|
|||||||
String implementationName = implName.replace( Mapper.CLASS_NAME_PLACEHOLDER,
|
String implementationName = implName.replace( Mapper.CLASS_NAME_PLACEHOLDER,
|
||||||
Mapper.getFlatName( mapperElement ) );
|
Mapper.getFlatName( mapperElement ) );
|
||||||
|
|
||||||
Type decoratorType = typeFactory.getType( decoratorPrism.value() );
|
Type decoratorType = typeFactory.getType( decorator.value().get() );
|
||||||
DecoratorConstructor decoratorConstructor = new DecoratorConstructor(
|
DecoratorConstructor decoratorConstructor = new DecoratorConstructor(
|
||||||
implementationName,
|
implementationName,
|
||||||
implementationName + "_",
|
implementationName + "_",
|
||||||
|
@ -20,7 +20,7 @@ import org.mapstruct.ap.internal.model.common.Type;
|
|||||||
import org.mapstruct.ap.internal.model.source.Method;
|
import org.mapstruct.ap.internal.model.source.Method;
|
||||||
import org.mapstruct.ap.internal.model.source.SelectionParameters;
|
import org.mapstruct.ap.internal.model.source.SelectionParameters;
|
||||||
import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria;
|
import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.util.Message;
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
import org.mapstruct.ap.internal.util.Strings;
|
import org.mapstruct.ap.internal.util.Strings;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ public class MapMappingMethod extends NormalTypeMappingMethod {
|
|||||||
|
|
||||||
private FormattingParameters keyFormattingParameters;
|
private FormattingParameters keyFormattingParameters;
|
||||||
private FormattingParameters valueFormattingParameters;
|
private FormattingParameters valueFormattingParameters;
|
||||||
private NullValueMappingStrategyPrism nullValueMappingStrategy;
|
private NullValueMappingStrategyGem nullValueMappingStrategy;
|
||||||
private SelectionParameters keySelectionParameters;
|
private SelectionParameters keySelectionParameters;
|
||||||
private SelectionParameters valueSelectionParameters;
|
private SelectionParameters valueSelectionParameters;
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ public class MapMappingMethod extends NormalTypeMappingMethod {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder nullValueMappingStrategy(NullValueMappingStrategyPrism nullValueMappingStrategy) {
|
public Builder nullValueMappingStrategy(NullValueMappingStrategyGem nullValueMappingStrategy) {
|
||||||
this.nullValueMappingStrategy = nullValueMappingStrategy;
|
this.nullValueMappingStrategy = nullValueMappingStrategy;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -34,9 +34,9 @@ import org.mapstruct.ap.internal.model.source.DelegatingOptions;
|
|||||||
import org.mapstruct.ap.internal.model.source.Method;
|
import org.mapstruct.ap.internal.model.source.Method;
|
||||||
import org.mapstruct.ap.internal.model.source.SelectionParameters;
|
import org.mapstruct.ap.internal.model.source.SelectionParameters;
|
||||||
import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria;
|
import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria;
|
||||||
import org.mapstruct.ap.internal.prism.BuilderPrism;
|
import org.mapstruct.ap.internal.gem.BuilderGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.util.Message;
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
import org.mapstruct.ap.internal.util.NativeTypes;
|
import org.mapstruct.ap.internal.util.NativeTypes;
|
||||||
import org.mapstruct.ap.internal.util.Strings;
|
import org.mapstruct.ap.internal.util.Strings;
|
||||||
@ -48,8 +48,8 @@ import static org.mapstruct.ap.internal.model.ForgedMethod.forElementMapping;
|
|||||||
import static org.mapstruct.ap.internal.model.ForgedMethod.forParameterMapping;
|
import static org.mapstruct.ap.internal.model.ForgedMethod.forParameterMapping;
|
||||||
import static org.mapstruct.ap.internal.model.ForgedMethod.forPropertyMapping;
|
import static org.mapstruct.ap.internal.model.ForgedMethod.forPropertyMapping;
|
||||||
import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT;
|
import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT;
|
||||||
import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT;
|
import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT;
|
||||||
import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_NULL;
|
import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the mapping between a source and target property, e.g. from {@code String Source#foo} to
|
* Represents the mapping between a source and target property, e.g. from {@code String Source#foo} to
|
||||||
@ -109,8 +109,8 @@ public class PropertyMapping extends ModelElement {
|
|||||||
public T targetWriteAccessor(Accessor targetWriteAccessor) {
|
public T targetWriteAccessor(Accessor targetWriteAccessor) {
|
||||||
this.targetWriteAccessor = targetWriteAccessor;
|
this.targetWriteAccessor = targetWriteAccessor;
|
||||||
this.targetType = ctx.getTypeFactory().getType( targetWriteAccessor.getAccessedType() );
|
this.targetType = ctx.getTypeFactory().getType( targetWriteAccessor.getAccessedType() );
|
||||||
BuilderPrism builderPrism = method.getOptions().getBeanMapping().getBuilderPrism();
|
BuilderGem builder = method.getOptions().getBeanMapping().getBuilder();
|
||||||
this.targetBuilderType = ctx.getTypeFactory().builderTypeFor( this.targetType, builderPrism );
|
this.targetBuilderType = ctx.getTypeFactory().builderTypeFor( this.targetType, builder );
|
||||||
this.targetWriteAccessorType = targetWriteAccessor.getAccessorType();
|
this.targetWriteAccessorType = targetWriteAccessor.getAccessorType();
|
||||||
return (T) this;
|
return (T) this;
|
||||||
}
|
}
|
||||||
@ -157,8 +157,8 @@ public class PropertyMapping extends ModelElement {
|
|||||||
private MappingReferences forgeMethodWithMappingReferences;
|
private MappingReferences forgeMethodWithMappingReferences;
|
||||||
private boolean forceUpdateMethod;
|
private boolean forceUpdateMethod;
|
||||||
private boolean forgedNamedBased = true;
|
private boolean forgedNamedBased = true;
|
||||||
private NullValueCheckStrategyPrism nvcs;
|
private NullValueCheckStrategyGem nvcs;
|
||||||
private NullValuePropertyMappingStrategyPrism nvpms;
|
private NullValuePropertyMappingStrategyGem nvpms;
|
||||||
|
|
||||||
PropertyMappingBuilder() {
|
PropertyMappingBuilder() {
|
||||||
super( PropertyMappingBuilder.class );
|
super( PropertyMappingBuilder.class );
|
||||||
|
@ -5,16 +5,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.model;
|
package org.mapstruct.ap.internal.model;
|
||||||
|
|
||||||
import static org.mapstruct.ap.internal.prism.MappingConstantsPrism.ANY_REMAINING;
|
|
||||||
import static org.mapstruct.ap.internal.prism.MappingConstantsPrism.ANY_UNMAPPED;
|
|
||||||
import static org.mapstruct.ap.internal.prism.MappingConstantsPrism.NULL;
|
|
||||||
import static org.mapstruct.ap.internal.util.Collections.first;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
import javax.lang.model.util.Types;
|
import javax.lang.model.util.Types;
|
||||||
|
|
||||||
@ -23,10 +17,15 @@ import org.mapstruct.ap.internal.model.common.Type;
|
|||||||
import org.mapstruct.ap.internal.model.source.Method;
|
import org.mapstruct.ap.internal.model.source.Method;
|
||||||
import org.mapstruct.ap.internal.model.source.SelectionParameters;
|
import org.mapstruct.ap.internal.model.source.SelectionParameters;
|
||||||
import org.mapstruct.ap.internal.model.source.ValueMappingOptions;
|
import org.mapstruct.ap.internal.model.source.ValueMappingOptions;
|
||||||
import org.mapstruct.ap.internal.prism.BeanMappingPrism;
|
import org.mapstruct.ap.internal.gem.BeanMappingGem;
|
||||||
import org.mapstruct.ap.internal.util.Message;
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
import org.mapstruct.ap.internal.util.Strings;
|
import org.mapstruct.ap.internal.util.Strings;
|
||||||
|
|
||||||
|
import static org.mapstruct.ap.internal.gem.MappingConstantsGem.ANY_REMAINING;
|
||||||
|
import static org.mapstruct.ap.internal.gem.MappingConstantsGem.ANY_UNMAPPED;
|
||||||
|
import static org.mapstruct.ap.internal.gem.MappingConstantsGem.NULL;
|
||||||
|
import static org.mapstruct.ap.internal.util.Collections.first;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link ValueMappingMethod} which maps one value type to another, optionally configured by one or more
|
* A {@link ValueMappingMethod} which maps one value type to another, optionally configured by one or more
|
||||||
* {@link ValueMappingOptions}s. For now, only enum-to-enum mapping is supported.
|
* {@link ValueMappingOptions}s. For now, only enum-to-enum mapping is supported.
|
||||||
@ -212,11 +211,11 @@ public class ValueMappingMethod extends MappingMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private SelectionParameters getSelectionParameters(Method method, Types typeUtils) {
|
private SelectionParameters getSelectionParameters(Method method, Types typeUtils) {
|
||||||
BeanMappingPrism beanMappingPrism = BeanMappingPrism.getInstanceOn( method.getExecutable() );
|
BeanMappingGem beanMapping = BeanMappingGem.instanceOn( method.getExecutable() );
|
||||||
if ( beanMappingPrism != null ) {
|
if ( beanMapping != null ) {
|
||||||
List<TypeMirror> qualifiers = beanMappingPrism.qualifiedBy();
|
List<TypeMirror> qualifiers = beanMapping.qualifiedBy().get();
|
||||||
List<String> qualifyingNames = beanMappingPrism.qualifiedByName();
|
List<String> qualifyingNames = beanMapping.qualifiedByName().get();
|
||||||
TypeMirror resultType = beanMappingPrism.resultType();
|
TypeMirror resultType = beanMapping.resultType().get();
|
||||||
return new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils );
|
return new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils );
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.model.assignment;
|
package org.mapstruct.ap.internal.model.assignment;
|
||||||
|
|
||||||
import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS;
|
import static org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem.ALWAYS;
|
||||||
import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.IGNORE;
|
import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.IGNORE;
|
||||||
import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT;
|
import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -16,8 +16,8 @@ import java.util.Set;
|
|||||||
import org.mapstruct.ap.internal.model.common.Assignment;
|
import org.mapstruct.ap.internal.model.common.Assignment;
|
||||||
import org.mapstruct.ap.internal.model.common.Type;
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This wrapper handles the situation where an assignment is done for an update method.
|
* This wrapper handles the situation where an assignment is done for an update method.
|
||||||
@ -41,8 +41,8 @@ public class ExistingInstanceSetterWrapperForCollectionsAndMaps
|
|||||||
public ExistingInstanceSetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment,
|
public ExistingInstanceSetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment,
|
||||||
List<Type> thrownTypesToExclude,
|
List<Type> thrownTypesToExclude,
|
||||||
Type targetType,
|
Type targetType,
|
||||||
NullValueCheckStrategyPrism nvcs,
|
NullValueCheckStrategyGem nvcs,
|
||||||
NullValuePropertyMappingStrategyPrism nvpms,
|
NullValuePropertyMappingStrategyGem nvpms,
|
||||||
TypeFactory typeFactory,
|
TypeFactory typeFactory,
|
||||||
boolean fieldAssignment) {
|
boolean fieldAssignment) {
|
||||||
|
|
||||||
|
@ -10,12 +10,12 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.mapstruct.ap.internal.model.common.Assignment;
|
import org.mapstruct.ap.internal.model.common.Assignment;
|
||||||
import org.mapstruct.ap.internal.model.common.Type;
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem;
|
||||||
|
|
||||||
import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS;
|
import static org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem.ALWAYS;
|
||||||
import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.IGNORE;
|
import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.IGNORE;
|
||||||
import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT;
|
import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the assignment in a target setter.
|
* Wraps the assignment in a target setter.
|
||||||
@ -92,8 +92,8 @@ public class SetterWrapper extends AssignmentWrapper {
|
|||||||
*
|
*
|
||||||
* @return include a null check
|
* @return include a null check
|
||||||
*/
|
*/
|
||||||
public static boolean doSourceNullCheck(Assignment rhs, NullValueCheckStrategyPrism nvcs,
|
public static boolean doSourceNullCheck(Assignment rhs, NullValueCheckStrategyGem nvcs,
|
||||||
NullValuePropertyMappingStrategyPrism nvpms, Type targetType) {
|
NullValuePropertyMappingStrategyGem nvpms, Type targetType) {
|
||||||
return !rhs.isSourceReferenceParameter()
|
return !rhs.isSourceReferenceParameter()
|
||||||
&& !rhs.getSourceType().isPrimitive()
|
&& !rhs.getSourceType().isPrimitive()
|
||||||
&& (ALWAYS == nvcs
|
&& (ALWAYS == nvcs
|
||||||
|
@ -20,8 +20,8 @@ import org.mapstruct.ap.internal.model.common.Type;
|
|||||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
||||||
import org.mapstruct.ap.internal.model.source.MappingOptions;
|
import org.mapstruct.ap.internal.model.source.MappingOptions;
|
||||||
import org.mapstruct.ap.internal.model.source.Method;
|
import org.mapstruct.ap.internal.model.source.Method;
|
||||||
import org.mapstruct.ap.internal.prism.BuilderPrism;
|
import org.mapstruct.ap.internal.gem.BuilderGem;
|
||||||
import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.util.FormattingMessager;
|
import org.mapstruct.ap.internal.util.FormattingMessager;
|
||||||
import org.mapstruct.ap.internal.util.Message;
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
import org.mapstruct.ap.internal.util.Strings;
|
import org.mapstruct.ap.internal.util.Strings;
|
||||||
@ -161,7 +161,7 @@ public class TargetReference extends AbstractReference {
|
|||||||
private List<PropertyEntry> getTargetEntries(Type type, String[] entryNames) {
|
private List<PropertyEntry> getTargetEntries(Type type, String[] entryNames) {
|
||||||
|
|
||||||
// initialize
|
// initialize
|
||||||
CollectionMappingStrategyPrism cms = method.getOptions().getMapper().getCollectionMappingStrategy();
|
CollectionMappingStrategyGem cms = method.getOptions().getMapper().getCollectionMappingStrategy();
|
||||||
List<PropertyEntry> targetEntries = new ArrayList<>();
|
List<PropertyEntry> targetEntries = new ArrayList<>();
|
||||||
Type nextType = type;
|
Type nextType = type;
|
||||||
|
|
||||||
@ -202,8 +202,8 @@ public class TargetReference extends AbstractReference {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BuilderPrism builderPrism = method.getOptions().getBeanMapping().getBuilderPrism();
|
BuilderGem builder = method.getOptions().getBeanMapping().getBuilder();
|
||||||
builderType = typeFactory.builderTypeFor( nextType, builderPrism );
|
builderType = typeFactory.builderTypeFor( nextType, builder );
|
||||||
propertyEntry = PropertyEntry.forTargetReference( fullName,
|
propertyEntry = PropertyEntry.forTargetReference( fullName,
|
||||||
targetReadAccessor,
|
targetReadAccessor,
|
||||||
targetWriteAccessor,
|
targetWriteAccessor,
|
||||||
@ -270,8 +270,8 @@ public class TargetReference extends AbstractReference {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BuilderPrism builderPrism = method.getOptions().getBeanMapping().getBuilderPrism();
|
BuilderGem builder = method.getOptions().getBeanMapping().getBuilder();
|
||||||
return typeFactory.effectiveResultTypeFor( type, builderPrism );
|
return typeFactory.effectiveResultTypeFor( type, builder );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,9 +11,9 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.lang.model.element.VariableElement;
|
import javax.lang.model.element.VariableElement;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.prism.ContextPrism;
|
import org.mapstruct.ap.internal.gem.ContextGem;
|
||||||
import org.mapstruct.ap.internal.prism.MappingTargetPrism;
|
import org.mapstruct.ap.internal.gem.MappingTargetGem;
|
||||||
import org.mapstruct.ap.internal.prism.TargetTypePrism;
|
import org.mapstruct.ap.internal.gem.TargetTypeGem;
|
||||||
import org.mapstruct.ap.internal.util.Collections;
|
import org.mapstruct.ap.internal.util.Collections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -117,9 +117,9 @@ public class Parameter extends ModelElement {
|
|||||||
return new Parameter(
|
return new Parameter(
|
||||||
element.getSimpleName().toString(),
|
element.getSimpleName().toString(),
|
||||||
parameterType,
|
parameterType,
|
||||||
MappingTargetPrism.getInstanceOn( element ) != null,
|
MappingTargetGem.instanceOn( element ) != null,
|
||||||
TargetTypePrism.getInstanceOn( element ) != null,
|
TargetTypeGem.instanceOn( element ) != null,
|
||||||
ContextPrism.getInstanceOn( element ) != null,
|
ContextGem.instanceOn( element ) != null,
|
||||||
isVarArgs
|
isVarArgs
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import javax.lang.model.util.ElementFilter;
|
|||||||
import javax.lang.model.util.Elements;
|
import javax.lang.model.util.Elements;
|
||||||
import javax.lang.model.util.Types;
|
import javax.lang.model.util.Types;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.util.AccessorNamingUtils;
|
import org.mapstruct.ap.internal.util.AccessorNamingUtils;
|
||||||
import org.mapstruct.ap.internal.util.Executables;
|
import org.mapstruct.ap.internal.util.Executables;
|
||||||
import org.mapstruct.ap.internal.util.Fields;
|
import org.mapstruct.ap.internal.util.Fields;
|
||||||
@ -536,7 +536,7 @@ public class Type extends ModelElement implements Comparable<Type> {
|
|||||||
* @param cmStrategy collection mapping strategy
|
* @param cmStrategy collection mapping strategy
|
||||||
* @return an unmodifiable map of all write accessors indexed by property name
|
* @return an unmodifiable map of all write accessors indexed by property name
|
||||||
*/
|
*/
|
||||||
public Map<String, Accessor> getPropertyWriteAccessors( CollectionMappingStrategyPrism cmStrategy ) {
|
public Map<String, Accessor> getPropertyWriteAccessors( CollectionMappingStrategyGem cmStrategy ) {
|
||||||
// collect all candidate target accessors
|
// collect all candidate target accessors
|
||||||
List<Accessor> candidates = new ArrayList<>( getSetters() );
|
List<Accessor> candidates = new ArrayList<>( getSetters() );
|
||||||
candidates.addAll( getAlternativeTargetAccessors() );
|
candidates.addAll( getAlternativeTargetAccessors() );
|
||||||
@ -554,15 +554,15 @@ public class Type extends ModelElement implements Comparable<Type> {
|
|||||||
// A target access is in general a setter method on the target object. However, in case of collections,
|
// A target access is in general a setter method on the target object. However, in case of collections,
|
||||||
// the current target accessor can also be a getter method.
|
// the current target accessor can also be a getter method.
|
||||||
// The following if block, checks if the target accessor should be overruled by an add method.
|
// The following if block, checks if the target accessor should be overruled by an add method.
|
||||||
if ( cmStrategy == CollectionMappingStrategyPrism.SETTER_PREFERRED
|
if ( cmStrategy == CollectionMappingStrategyGem.SETTER_PREFERRED
|
||||||
|| cmStrategy == CollectionMappingStrategyPrism.ADDER_PREFERRED
|
|| cmStrategy == CollectionMappingStrategyGem.ADDER_PREFERRED
|
||||||
|| cmStrategy == CollectionMappingStrategyPrism.TARGET_IMMUTABLE ) {
|
|| cmStrategy == CollectionMappingStrategyGem.TARGET_IMMUTABLE ) {
|
||||||
|
|
||||||
// first check if there's a setter method.
|
// first check if there's a setter method.
|
||||||
Accessor adderMethod = null;
|
Accessor adderMethod = null;
|
||||||
if ( candidate.getAccessorType() == AccessorType.SETTER
|
if ( candidate.getAccessorType() == AccessorType.SETTER
|
||||||
// ok, the current accessor is a setter. So now the strategy determines what to use
|
// ok, the current accessor is a setter. So now the strategy determines what to use
|
||||||
&& cmStrategy == CollectionMappingStrategyPrism.ADDER_PREFERRED ) {
|
&& cmStrategy == CollectionMappingStrategyGem.ADDER_PREFERRED ) {
|
||||||
adderMethod = getAdderForType( targetType, targetPropertyName );
|
adderMethod = getAdderForType( targetType, targetPropertyName );
|
||||||
}
|
}
|
||||||
else if ( candidate.getAccessorType() == AccessorType.GETTER ) {
|
else if ( candidate.getAccessorType() == AccessorType.GETTER ) {
|
||||||
|
@ -39,7 +39,7 @@ import javax.lang.model.type.WildcardType;
|
|||||||
import javax.lang.model.util.Elements;
|
import javax.lang.model.util.Elements;
|
||||||
import javax.lang.model.util.Types;
|
import javax.lang.model.util.Types;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.prism.BuilderPrism;
|
import org.mapstruct.ap.internal.gem.BuilderGem;
|
||||||
import org.mapstruct.ap.internal.util.AnnotationProcessingException;
|
import org.mapstruct.ap.internal.util.AnnotationProcessingException;
|
||||||
import org.mapstruct.ap.internal.util.Collections;
|
import org.mapstruct.ap.internal.util.Collections;
|
||||||
import org.mapstruct.ap.internal.util.Extractor;
|
import org.mapstruct.ap.internal.util.Extractor;
|
||||||
@ -517,8 +517,8 @@ public class TypeFactory {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BuilderInfo findBuilder(TypeMirror type, BuilderPrism builderPrism, boolean report) {
|
private BuilderInfo findBuilder(TypeMirror type, BuilderGem builderGem, boolean report) {
|
||||||
if ( builderPrism != null && builderPrism.disableBuilder() ) {
|
if ( builderGem != null && builderGem.disableBuilder().get() ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -631,17 +631,17 @@ public class TypeFactory {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderType builderTypeFor( Type type, BuilderPrism builderPrism ) {
|
public BuilderType builderTypeFor( Type type, BuilderGem builder ) {
|
||||||
if ( type != null ) {
|
if ( type != null ) {
|
||||||
BuilderInfo builderInfo = findBuilder( type.getTypeMirror(), builderPrism, true );
|
BuilderInfo builderInfo = findBuilder( type.getTypeMirror(), builder, true );
|
||||||
return BuilderType.create( builderInfo, type, this, this.typeUtils );
|
return BuilderType.create( builderInfo, type, this, this.typeUtils );
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type effectiveResultTypeFor( Type type, BuilderPrism builderPrism ) {
|
public Type effectiveResultTypeFor( Type type, BuilderGem builder ) {
|
||||||
if ( type != null ) {
|
if ( type != null ) {
|
||||||
BuilderInfo builderInfo = findBuilder( type.getTypeMirror(), builderPrism, false );
|
BuilderInfo builderInfo = findBuilder( type.getTypeMirror(), builder, false );
|
||||||
BuilderType builderType = BuilderType.create( builderInfo, type, this, this.typeUtils );
|
BuilderType builderType = BuilderType.create( builderInfo, type, this, this.typeUtils );
|
||||||
return builderType != null ? builderType.getBuilder() : type;
|
return builderType != null ? builderType.getBuilder() : type;
|
||||||
}
|
}
|
||||||
|
@ -8,19 +8,20 @@ package org.mapstruct.ap.internal.model.source;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import javax.lang.model.element.AnnotationMirror;
|
import javax.lang.model.element.AnnotationMirror;
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import javax.lang.model.type.TypeKind;
|
|
||||||
import javax.lang.model.util.Types;
|
import javax.lang.model.util.Types;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
||||||
import org.mapstruct.ap.internal.prism.BeanMappingPrism;
|
import org.mapstruct.ap.internal.gem.BeanMappingGem;
|
||||||
import org.mapstruct.ap.internal.prism.BuilderPrism;
|
import org.mapstruct.ap.internal.gem.BuilderGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.util.FormattingMessager;
|
import org.mapstruct.ap.internal.util.FormattingMessager;
|
||||||
import org.mapstruct.ap.internal.util.Message;
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
|
import org.mapstruct.tools.gem.GemValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an bean mapping as configured via {@code @BeanMapping}.
|
* Represents an bean mapping as configured via {@code @BeanMapping}.
|
||||||
@ -30,7 +31,7 @@ import org.mapstruct.ap.internal.util.Message;
|
|||||||
public class BeanMappingOptions extends DelegatingOptions {
|
public class BeanMappingOptions extends DelegatingOptions {
|
||||||
|
|
||||||
private final SelectionParameters selectionParameters;
|
private final SelectionParameters selectionParameters;
|
||||||
private final BeanMappingPrism prism;
|
private final BeanMappingGem beanMapping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a mapping for inheritance. Will set
|
* creates a mapping for inheritance. Will set
|
||||||
@ -40,17 +41,17 @@ public class BeanMappingOptions extends DelegatingOptions {
|
|||||||
public static BeanMappingOptions forInheritance(BeanMappingOptions beanMapping) {
|
public static BeanMappingOptions forInheritance(BeanMappingOptions beanMapping) {
|
||||||
BeanMappingOptions options = new BeanMappingOptions(
|
BeanMappingOptions options = new BeanMappingOptions(
|
||||||
SelectionParameters.forInheritance( beanMapping.selectionParameters ),
|
SelectionParameters.forInheritance( beanMapping.selectionParameters ),
|
||||||
beanMapping.prism,
|
beanMapping.beanMapping,
|
||||||
beanMapping
|
beanMapping
|
||||||
);
|
);
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BeanMappingOptions getInstanceOn(BeanMappingPrism prism, MapperOptions mapperOptions,
|
public static BeanMappingOptions getInstanceOn(BeanMappingGem beanMapping, MapperOptions mapperOptions,
|
||||||
ExecutableElement method, FormattingMessager messager,
|
ExecutableElement method, FormattingMessager messager,
|
||||||
Types typeUtils, TypeFactory typeFactory
|
Types typeUtils, TypeFactory typeFactory
|
||||||
) {
|
) {
|
||||||
if ( prism == null || !isConsistent( prism, method, messager ) ) {
|
if ( beanMapping == null || !isConsistent( beanMapping, method, messager ) ) {
|
||||||
BeanMappingOptions options = new BeanMappingOptions( null, null, mapperOptions );
|
BeanMappingOptions options = new BeanMappingOptions( null, null, mapperOptions );
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
@ -62,28 +63,32 @@ public class BeanMappingOptions extends DelegatingOptions {
|
|||||||
Objects.requireNonNull( typeFactory );
|
Objects.requireNonNull( typeFactory );
|
||||||
|
|
||||||
SelectionParameters selectionParameters = new SelectionParameters(
|
SelectionParameters selectionParameters = new SelectionParameters(
|
||||||
prism.qualifiedBy(),
|
beanMapping.qualifiedBy().get(),
|
||||||
prism.qualifiedByName(),
|
beanMapping.qualifiedByName().get(),
|
||||||
TypeKind.VOID != prism.resultType().getKind() ? prism.resultType() : null,
|
beanMapping.resultType().getValue(),
|
||||||
typeUtils
|
typeUtils
|
||||||
);
|
);
|
||||||
|
|
||||||
//TODO Do we want to add the reporting policy to the BeanMapping as well? To give more granular support?
|
//TODO Do we want to add the reporting policy to the BeanMapping as well? To give more granular support?
|
||||||
BeanMappingOptions options = new BeanMappingOptions( selectionParameters, prism, mapperOptions );
|
BeanMappingOptions options = new BeanMappingOptions(
|
||||||
|
selectionParameters,
|
||||||
|
beanMapping,
|
||||||
|
mapperOptions
|
||||||
|
);
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isConsistent(BeanMappingPrism prism, ExecutableElement method,
|
private static boolean isConsistent(BeanMappingGem gem, ExecutableElement method,
|
||||||
FormattingMessager messager) {
|
FormattingMessager messager) {
|
||||||
if ( TypeKind.VOID == prism.resultType().getKind()
|
if ( !gem.resultType().hasValue()
|
||||||
&& prism.qualifiedBy().isEmpty()
|
&& !gem.qualifiedBy().hasValue()
|
||||||
&& prism.qualifiedByName().isEmpty()
|
&& !gem.qualifiedByName().hasValue()
|
||||||
&& prism.ignoreUnmappedSourceProperties().isEmpty()
|
&& !gem.ignoreUnmappedSourceProperties().hasValue()
|
||||||
&& null == prism.values.nullValueCheckStrategy()
|
&& !gem.nullValueCheckStrategy().hasValue()
|
||||||
&& null == prism.values.nullValuePropertyMappingStrategy()
|
&& !gem.nullValuePropertyMappingStrategy().hasValue()
|
||||||
&& null == prism.values.nullValueMappingStrategy()
|
&& !gem.nullValueMappingStrategy().hasValue()
|
||||||
&& null == prism.values.ignoreByDefault()
|
&& !gem.ignoreByDefault().hasValue()
|
||||||
&& null == prism.values.builder() ) {
|
&& !gem.builder().hasValue() ) {
|
||||||
|
|
||||||
messager.printMessage( method, Message.BEANMAPPING_NO_ELEMENTS );
|
messager.printMessage( method, Message.BEANMAPPING_NO_ELEMENTS );
|
||||||
return false;
|
return false;
|
||||||
@ -91,39 +96,49 @@ public class BeanMappingOptions extends DelegatingOptions {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BeanMappingOptions(SelectionParameters selectionParameters, BeanMappingPrism prism,
|
private BeanMappingOptions(SelectionParameters selectionParameters,
|
||||||
|
BeanMappingGem beanMapping,
|
||||||
DelegatingOptions next) {
|
DelegatingOptions next) {
|
||||||
super( next );
|
super( next );
|
||||||
this.selectionParameters = selectionParameters;
|
this.selectionParameters = selectionParameters;
|
||||||
this.prism = prism;
|
this.beanMapping = beanMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Mapping, @BeanMapping
|
// @Mapping, @BeanMapping
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NullValueCheckStrategyPrism getNullValueCheckStrategy() {
|
public NullValueCheckStrategyGem getNullValueCheckStrategy() {
|
||||||
return null == prism || null == prism.values.nullValueCheckStrategy() ?
|
return Optional.ofNullable( beanMapping ).map( BeanMappingGem::nullValueCheckStrategy )
|
||||||
next().getNullValueCheckStrategy()
|
.filter( GemValue::hasValue )
|
||||||
: NullValueCheckStrategyPrism.valueOf( prism.nullValueCheckStrategy() );
|
.map( GemValue::getValue )
|
||||||
|
.map( NullValueCheckStrategyGem::valueOf )
|
||||||
|
.orElse( next().getNullValueCheckStrategy() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() {
|
public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() {
|
||||||
return null == prism || null == prism.values.nullValuePropertyMappingStrategy() ?
|
return Optional.ofNullable( beanMapping ).map( BeanMappingGem::nullValuePropertyMappingStrategy )
|
||||||
next().getNullValuePropertyMappingStrategy()
|
.filter( GemValue::hasValue )
|
||||||
: NullValuePropertyMappingStrategyPrism.valueOf( prism.nullValuePropertyMappingStrategy() );
|
.map( GemValue::getValue )
|
||||||
|
.map( NullValuePropertyMappingStrategyGem::valueOf )
|
||||||
|
.orElse( next().getNullValuePropertyMappingStrategy() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NullValueMappingStrategyPrism getNullValueMappingStrategy() {
|
public NullValueMappingStrategyGem getNullValueMappingStrategy() {
|
||||||
return null == prism || null == prism.values.nullValueMappingStrategy() ?
|
return Optional.ofNullable( beanMapping ).map( BeanMappingGem::nullValueMappingStrategy )
|
||||||
next().getNullValueMappingStrategy()
|
.filter( GemValue::hasValue )
|
||||||
: NullValueMappingStrategyPrism.valueOf( prism.nullValueMappingStrategy() );
|
.map( GemValue::getValue )
|
||||||
|
.map( NullValueMappingStrategyGem::valueOf )
|
||||||
|
.orElse( next().getNullValueMappingStrategy() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BuilderPrism getBuilderPrism() {
|
public BuilderGem getBuilder() {
|
||||||
return null == prism || null == prism.values.builder() ? next().getBuilderPrism() : prism.builder();
|
return Optional.ofNullable( beanMapping ).map( BeanMappingGem::builder )
|
||||||
|
.filter( GemValue::hasValue )
|
||||||
|
.map( GemValue::getValue )
|
||||||
|
.orElse( next().getBuilder() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// @BeanMapping specific
|
// @BeanMapping specific
|
||||||
@ -133,19 +148,23 @@ public class BeanMappingOptions extends DelegatingOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isignoreByDefault() {
|
public boolean isignoreByDefault() {
|
||||||
return null == prism ? false : prism.ignoreByDefault();
|
return Optional.ofNullable( beanMapping ).map( BeanMappingGem::ignoreByDefault )
|
||||||
|
.map( GemValue::get )
|
||||||
|
.orElse( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getIgnoreUnmappedSourceProperties() {
|
public List<String> getIgnoreUnmappedSourceProperties() {
|
||||||
return null == prism ? Collections.emptyList() : prism.ignoreUnmappedSourceProperties();
|
return Optional.ofNullable( beanMapping ).map( BeanMappingGem::ignoreUnmappedSourceProperties )
|
||||||
|
.map( GemValue::get )
|
||||||
|
.orElse( Collections.emptyList() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnnotationMirror getMirror() {
|
public AnnotationMirror getMirror() {
|
||||||
return null == prism ? null : prism.mirror;
|
return Optional.ofNullable( beanMapping ).map( BeanMappingGem::mirror ).orElse( null );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasAnnotation() {
|
public boolean hasAnnotation() {
|
||||||
return prism != null;
|
return beanMapping != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,35 +10,35 @@ import java.util.Set;
|
|||||||
import javax.lang.model.type.DeclaredType;
|
import javax.lang.model.type.DeclaredType;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.option.Options;
|
import org.mapstruct.ap.internal.option.Options;
|
||||||
import org.mapstruct.ap.internal.prism.BuilderPrism;
|
import org.mapstruct.ap.internal.gem.BuilderGem;
|
||||||
import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.InjectionStrategyPrism;
|
import org.mapstruct.ap.internal.gem.InjectionStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.MapperPrism;
|
import org.mapstruct.ap.internal.gem.MapperGem;
|
||||||
import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism;
|
import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.ReportingPolicyPrism;
|
import org.mapstruct.ap.internal.gem.ReportingPolicyGem;
|
||||||
|
|
||||||
public class DefaultOptions extends DelegatingOptions {
|
public class DefaultOptions extends DelegatingOptions {
|
||||||
|
|
||||||
private final MapperPrism prism;
|
private final MapperGem mapper;
|
||||||
private final Options options;
|
private final Options options;
|
||||||
|
|
||||||
DefaultOptions(MapperPrism prism, Options options) {
|
DefaultOptions(MapperGem mapper, Options options) {
|
||||||
super( null );
|
super( null );
|
||||||
this.prism = prism;
|
this.mapper = mapper;
|
||||||
this.options = options;
|
this.options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String implementationName() {
|
public String implementationName() {
|
||||||
return prism.implementationName();
|
return mapper.implementationName().getDefaultValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String implementationPackage() {
|
public String implementationPackage() {
|
||||||
return prism.implementationPackage();
|
return mapper.implementationPackage().getDefaultValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -52,21 +52,21 @@ public class DefaultOptions extends DelegatingOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReportingPolicyPrism unmappedTargetPolicy() {
|
public ReportingPolicyGem unmappedTargetPolicy() {
|
||||||
if ( options.getUnmappedTargetPolicy() != null ) {
|
if ( options.getUnmappedTargetPolicy() != null ) {
|
||||||
return options.getUnmappedTargetPolicy();
|
return options.getUnmappedTargetPolicy();
|
||||||
}
|
}
|
||||||
return ReportingPolicyPrism.valueOf( prism.unmappedTargetPolicy() );
|
return ReportingPolicyGem.valueOf( mapper.unmappedTargetPolicy().getDefaultValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReportingPolicyPrism unmappedSourcePolicy() {
|
public ReportingPolicyGem unmappedSourcePolicy() {
|
||||||
return ReportingPolicyPrism.valueOf( prism.unmappedSourcePolicy() );
|
return ReportingPolicyGem.valueOf( mapper.unmappedSourcePolicy().getDefaultValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReportingPolicyPrism typeConversionPolicy() {
|
public ReportingPolicyGem typeConversionPolicy() {
|
||||||
return ReportingPolicyPrism.valueOf( prism.typeConversionPolicy() );
|
return ReportingPolicyGem.valueOf( mapper.typeConversionPolicy().getDefaultValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -74,46 +74,47 @@ public class DefaultOptions extends DelegatingOptions {
|
|||||||
if ( options.getDefaultComponentModel() != null ) {
|
if ( options.getDefaultComponentModel() != null ) {
|
||||||
return options.getDefaultComponentModel();
|
return options.getDefaultComponentModel();
|
||||||
}
|
}
|
||||||
return prism.componentModel();
|
return mapper.componentModel().getDefaultValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MappingInheritanceStrategyPrism getMappingInheritanceStrategy() {
|
public MappingInheritanceStrategyGem getMappingInheritanceStrategy() {
|
||||||
return MappingInheritanceStrategyPrism.valueOf( prism.mappingInheritanceStrategy() );
|
return MappingInheritanceStrategyGem.valueOf( mapper.mappingInheritanceStrategy().getDefaultValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InjectionStrategyPrism getInjectionStrategy() {
|
public InjectionStrategyGem getInjectionStrategy() {
|
||||||
if ( options.getDefaultInjectionStrategy() != null ) {
|
if ( options.getDefaultInjectionStrategy() != null ) {
|
||||||
return InjectionStrategyPrism.valueOf( options.getDefaultInjectionStrategy().toUpperCase() );
|
return InjectionStrategyGem.valueOf( options.getDefaultInjectionStrategy().toUpperCase() );
|
||||||
}
|
}
|
||||||
return InjectionStrategyPrism.valueOf( prism.injectionStrategy() );
|
return InjectionStrategyGem.valueOf( mapper.injectionStrategy().getDefaultValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean isDisableSubMappingMethodsGeneration() {
|
public Boolean isDisableSubMappingMethodsGeneration() {
|
||||||
return prism.disableSubMappingMethodsGeneration();
|
return mapper.disableSubMappingMethodsGeneration().getDefaultValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// BeanMapping and Mapping
|
// BeanMapping and Mapping
|
||||||
|
|
||||||
public CollectionMappingStrategyPrism getCollectionMappingStrategy() {
|
public CollectionMappingStrategyGem getCollectionMappingStrategy() {
|
||||||
return CollectionMappingStrategyPrism.valueOf( prism.collectionMappingStrategy() );
|
return CollectionMappingStrategyGem.valueOf( mapper.collectionMappingStrategy().getDefaultValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public NullValueCheckStrategyPrism getNullValueCheckStrategy() {
|
public NullValueCheckStrategyGem getNullValueCheckStrategy() {
|
||||||
return NullValueCheckStrategyPrism.valueOf( prism.nullValueCheckStrategy() );
|
return NullValueCheckStrategyGem.valueOf( mapper.nullValueCheckStrategy().getDefaultValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() {
|
public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() {
|
||||||
return NullValuePropertyMappingStrategyPrism.valueOf( prism.nullValuePropertyMappingStrategy() );
|
return NullValuePropertyMappingStrategyGem.valueOf(
|
||||||
|
mapper.nullValuePropertyMappingStrategy().getDefaultValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public NullValueMappingStrategyPrism getNullValueMappingStrategy() {
|
public NullValueMappingStrategyGem getNullValueMappingStrategy() {
|
||||||
return NullValueMappingStrategyPrism.valueOf( prism.nullValueMappingStrategy() );
|
return NullValueMappingStrategyGem.valueOf( mapper.nullValueMappingStrategy().getDefaultValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderPrism getBuilderPrism() {
|
public BuilderGem getBuilder() {
|
||||||
// TODO: I realized this is not correct, however it needs to be null in order to keep downward compatibility
|
// 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
|
// 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 @MappingConfig and @Mapper.
|
||||||
|
@ -12,14 +12,14 @@ import java.util.stream.Collectors;
|
|||||||
import javax.lang.model.type.DeclaredType;
|
import javax.lang.model.type.DeclaredType;
|
||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.prism.BuilderPrism;
|
import org.mapstruct.ap.internal.gem.BuilderGem;
|
||||||
import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.InjectionStrategyPrism;
|
import org.mapstruct.ap.internal.gem.InjectionStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism;
|
import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.ReportingPolicyPrism;
|
import org.mapstruct.ap.internal.gem.ReportingPolicyGem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Chain Of Responsibility Pattern.
|
* Chain Of Responsibility Pattern.
|
||||||
@ -50,15 +50,15 @@ public abstract class DelegatingOptions {
|
|||||||
return next.imports();
|
return next.imports();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReportingPolicyPrism unmappedTargetPolicy() {
|
public ReportingPolicyGem unmappedTargetPolicy() {
|
||||||
return next.unmappedTargetPolicy();
|
return next.unmappedTargetPolicy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReportingPolicyPrism unmappedSourcePolicy() {
|
public ReportingPolicyGem unmappedSourcePolicy() {
|
||||||
return next.unmappedSourcePolicy();
|
return next.unmappedSourcePolicy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReportingPolicyPrism typeConversionPolicy() {
|
public ReportingPolicyGem typeConversionPolicy() {
|
||||||
return next.typeConversionPolicy();
|
return next.typeConversionPolicy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,11 +66,11 @@ public abstract class DelegatingOptions {
|
|||||||
return next.componentModel();
|
return next.componentModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MappingInheritanceStrategyPrism getMappingInheritanceStrategy() {
|
public MappingInheritanceStrategyGem getMappingInheritanceStrategy() {
|
||||||
return next.getMappingInheritanceStrategy();
|
return next.getMappingInheritanceStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InjectionStrategyPrism getInjectionStrategy() {
|
public InjectionStrategyGem getInjectionStrategy() {
|
||||||
return next.getInjectionStrategy();
|
return next.getInjectionStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,24 +80,24 @@ public abstract class DelegatingOptions {
|
|||||||
|
|
||||||
// BeanMapping and Mapping
|
// BeanMapping and Mapping
|
||||||
|
|
||||||
public CollectionMappingStrategyPrism getCollectionMappingStrategy() {
|
public CollectionMappingStrategyGem getCollectionMappingStrategy() {
|
||||||
return next.getCollectionMappingStrategy();
|
return next.getCollectionMappingStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public NullValueCheckStrategyPrism getNullValueCheckStrategy() {
|
public NullValueCheckStrategyGem getNullValueCheckStrategy() {
|
||||||
return next.getNullValueCheckStrategy();
|
return next.getNullValueCheckStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() {
|
public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() {
|
||||||
return next.getNullValuePropertyMappingStrategy();
|
return next.getNullValuePropertyMappingStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public NullValueMappingStrategyPrism getNullValueMappingStrategy() {
|
public NullValueMappingStrategyGem getNullValueMappingStrategy() {
|
||||||
return next.getNullValueMappingStrategy();
|
return next.getNullValueMappingStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BuilderPrism getBuilderPrism() {
|
public BuilderGem getBuilder() {
|
||||||
return next.getBuilderPrism();
|
return next.getBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
DelegatingOptions next() {
|
DelegatingOptions next() {
|
||||||
|
@ -5,16 +5,17 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.model.source;
|
package org.mapstruct.ap.internal.model.source;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import javax.lang.model.element.AnnotationMirror;
|
import javax.lang.model.element.AnnotationMirror;
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import javax.lang.model.type.TypeKind;
|
|
||||||
import javax.lang.model.util.Types;
|
import javax.lang.model.util.Types;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.model.common.FormattingParameters;
|
import org.mapstruct.ap.internal.model.common.FormattingParameters;
|
||||||
import org.mapstruct.ap.internal.prism.IterableMappingPrism;
|
import org.mapstruct.ap.internal.gem.IterableMappingGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.util.FormattingMessager;
|
import org.mapstruct.ap.internal.util.FormattingMessager;
|
||||||
import org.mapstruct.ap.internal.util.Message;
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
|
import org.mapstruct.tools.gem.GemValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an iterable mapping as configured via {@code @IterableMapping}.
|
* Represents an iterable mapping as configured via {@code @IterableMapping}.
|
||||||
@ -25,44 +26,45 @@ public class IterableMappingOptions extends DelegatingOptions {
|
|||||||
|
|
||||||
private final SelectionParameters selectionParameters;
|
private final SelectionParameters selectionParameters;
|
||||||
private final FormattingParameters formattingParameters;
|
private final FormattingParameters formattingParameters;
|
||||||
private final IterableMappingPrism prism;
|
private final IterableMappingGem iterableMapping;
|
||||||
|
|
||||||
public static IterableMappingOptions fromPrism(IterableMappingPrism prism,
|
public static IterableMappingOptions fromGem(IterableMappingGem iterableMapping,
|
||||||
MapperOptions mappperOptions, ExecutableElement method,
|
MapperOptions mappperOptions, ExecutableElement method,
|
||||||
FormattingMessager messager, Types typeUtils) {
|
FormattingMessager messager, Types typeUtils) {
|
||||||
|
|
||||||
if ( prism == null || !isConsistent( prism, method, messager ) ) {
|
if ( iterableMapping == null || !isConsistent( iterableMapping, method, messager ) ) {
|
||||||
IterableMappingOptions options = new IterableMappingOptions( null, null, null, mappperOptions );
|
IterableMappingOptions options = new IterableMappingOptions( null, null, null, mappperOptions );
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectionParameters selection = new SelectionParameters(
|
SelectionParameters selection = new SelectionParameters(
|
||||||
prism.qualifiedBy(),
|
iterableMapping.qualifiedBy().get(),
|
||||||
prism.qualifiedByName(),
|
iterableMapping.qualifiedByName().get(),
|
||||||
TypeKind.VOID != prism.elementTargetType().getKind() ? prism.elementTargetType() : null,
|
iterableMapping.elementTargetType().getValue(),
|
||||||
typeUtils
|
typeUtils
|
||||||
);
|
);
|
||||||
|
|
||||||
FormattingParameters formatting = new FormattingParameters(
|
FormattingParameters formatting = new FormattingParameters(
|
||||||
prism.dateFormat(),
|
iterableMapping.dateFormat().get(),
|
||||||
prism.numberFormat(),
|
iterableMapping.numberFormat().get(),
|
||||||
prism.mirror,
|
iterableMapping.mirror(),
|
||||||
prism.values.dateFormat(),
|
iterableMapping.dateFormat().getAnnotationValue(),
|
||||||
method
|
method
|
||||||
);
|
);
|
||||||
|
|
||||||
IterableMappingOptions options = new IterableMappingOptions( formatting, selection, prism, mappperOptions );
|
IterableMappingOptions options =
|
||||||
|
new IterableMappingOptions( formatting, selection, iterableMapping, mappperOptions );
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isConsistent(IterableMappingPrism prism, ExecutableElement method,
|
private static boolean isConsistent(IterableMappingGem gem, ExecutableElement method,
|
||||||
FormattingMessager messager) {
|
FormattingMessager messager) {
|
||||||
if ( prism.dateFormat().isEmpty()
|
if ( !gem.dateFormat().hasValue()
|
||||||
&& prism.numberFormat().isEmpty()
|
&& !gem.numberFormat().hasValue()
|
||||||
&& prism.qualifiedBy().isEmpty()
|
&& !gem.qualifiedBy().hasValue()
|
||||||
&& prism.qualifiedByName().isEmpty()
|
&& !gem.qualifiedByName().hasValue()
|
||||||
&& TypeKind.VOID == prism.elementTargetType().getKind()
|
&& !gem.elementTargetType().hasValue()
|
||||||
&& null == prism.values.nullValueMappingStrategy() ) {
|
&& !gem.nullValueMappingStrategy().hasValue() ) {
|
||||||
messager.printMessage( method, Message.ITERABLEMAPPING_NO_ELEMENTS );
|
messager.printMessage( method, Message.ITERABLEMAPPING_NO_ELEMENTS );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -70,11 +72,12 @@ public class IterableMappingOptions extends DelegatingOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private IterableMappingOptions(FormattingParameters formattingParameters, SelectionParameters selectionParameters,
|
private IterableMappingOptions(FormattingParameters formattingParameters, SelectionParameters selectionParameters,
|
||||||
IterableMappingPrism prism, DelegatingOptions next ) {
|
IterableMappingGem iterableMapping,
|
||||||
|
DelegatingOptions next) {
|
||||||
super( next );
|
super( next );
|
||||||
this.formattingParameters = formattingParameters;
|
this.formattingParameters = formattingParameters;
|
||||||
this.selectionParameters = selectionParameters;
|
this.selectionParameters = selectionParameters;
|
||||||
this.prism = prism;
|
this.iterableMapping = iterableMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelectionParameters getSelectionParameters() {
|
public SelectionParameters getSelectionParameters() {
|
||||||
@ -86,19 +89,21 @@ public class IterableMappingOptions extends DelegatingOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AnnotationMirror getMirror() {
|
public AnnotationMirror getMirror() {
|
||||||
return null == prism ? null : prism.mirror;
|
return Optional.ofNullable( iterableMapping ).map( IterableMappingGem::mirror ).orElse( null );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NullValueMappingStrategyPrism getNullValueMappingStrategy() {
|
public NullValueMappingStrategyGem getNullValueMappingStrategy() {
|
||||||
return null == prism || null == prism.values.nullValueMappingStrategy() ?
|
return Optional.ofNullable( iterableMapping ).map( IterableMappingGem::nullValueMappingStrategy )
|
||||||
next().getNullValueMappingStrategy()
|
.filter( GemValue::hasValue )
|
||||||
: NullValueMappingStrategyPrism.valueOf( prism.nullValueMappingStrategy() );
|
.map( GemValue::getValue )
|
||||||
|
.map( NullValueMappingStrategyGem::valueOf )
|
||||||
|
.orElse( next().getNullValueMappingStrategy() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasAnnotation() {
|
public boolean hasAnnotation() {
|
||||||
return prism != null;
|
return iterableMapping != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,17 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.model.source;
|
package org.mapstruct.ap.internal.model.source;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import javax.lang.model.element.AnnotationMirror;
|
import javax.lang.model.element.AnnotationMirror;
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import javax.lang.model.type.TypeKind;
|
|
||||||
import javax.lang.model.util.Types;
|
import javax.lang.model.util.Types;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.model.common.FormattingParameters;
|
import org.mapstruct.ap.internal.model.common.FormattingParameters;
|
||||||
import org.mapstruct.ap.internal.prism.MapMappingPrism;
|
import org.mapstruct.ap.internal.gem.MapMappingGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.util.FormattingMessager;
|
import org.mapstruct.ap.internal.util.FormattingMessager;
|
||||||
import org.mapstruct.ap.internal.util.Message;
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
|
import org.mapstruct.tools.gem.GemValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a map mapping as configured via {@code @MapMapping}.
|
* Represents a map mapping as configured via {@code @MapMapping}.
|
||||||
@ -27,44 +28,50 @@ public class MapMappingOptions extends DelegatingOptions {
|
|||||||
private final SelectionParameters valueSelectionParameters;
|
private final SelectionParameters valueSelectionParameters;
|
||||||
private final FormattingParameters keyFormattingParameters;
|
private final FormattingParameters keyFormattingParameters;
|
||||||
private final FormattingParameters valueFormattingParameters;
|
private final FormattingParameters valueFormattingParameters;
|
||||||
private final MapMappingPrism prism;
|
private final MapMappingGem mapMapping;
|
||||||
|
|
||||||
public static MapMappingOptions fromPrism(MapMappingPrism prism, MapperOptions mapperOptions,
|
public static MapMappingOptions fromGem(MapMappingGem mapMapping, MapperOptions mapperOptions,
|
||||||
ExecutableElement method,
|
ExecutableElement method, FormattingMessager messager, Types typeUtils) {
|
||||||
FormattingMessager messager, Types typeUtils) {
|
|
||||||
|
|
||||||
if ( prism == null || !isConsistent( prism, method, messager ) ) {
|
if ( mapMapping == null || !isConsistent( mapMapping, method, messager ) ) {
|
||||||
MapMappingOptions options = new MapMappingOptions( null, null, null, null, null, mapperOptions );
|
MapMappingOptions options = new MapMappingOptions(
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
mapperOptions
|
||||||
|
);
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectionParameters keySelection = new SelectionParameters(
|
SelectionParameters keySelection = new SelectionParameters(
|
||||||
prism.keyQualifiedBy(),
|
mapMapping.keyQualifiedBy().get(),
|
||||||
prism.keyQualifiedByName(),
|
mapMapping.keyQualifiedByName().get(),
|
||||||
TypeKind.VOID != prism.keyTargetType().getKind() ? prism.keyTargetType() : null,
|
mapMapping.keyTargetType().getValue(),
|
||||||
typeUtils
|
typeUtils
|
||||||
);
|
);
|
||||||
|
|
||||||
SelectionParameters valueSelection = new SelectionParameters(
|
SelectionParameters valueSelection = new SelectionParameters(
|
||||||
prism.valueQualifiedBy(),
|
mapMapping.valueQualifiedBy().get(),
|
||||||
prism.valueQualifiedByName(),
|
mapMapping.valueQualifiedByName().get(),
|
||||||
TypeKind.VOID != prism.valueTargetType().getKind() ? prism.valueTargetType() : null,
|
mapMapping.valueTargetType().getValue(),
|
||||||
typeUtils
|
typeUtils
|
||||||
);
|
);
|
||||||
|
|
||||||
FormattingParameters keyFormatting = new FormattingParameters(
|
FormattingParameters keyFormatting = new FormattingParameters(
|
||||||
prism.keyDateFormat(),
|
mapMapping.keyDateFormat().get(),
|
||||||
prism.keyNumberFormat(),
|
mapMapping.keyNumberFormat().get(),
|
||||||
prism.mirror,
|
mapMapping.mirror(),
|
||||||
prism.values.keyDateFormat(),
|
mapMapping.keyDateFormat().getAnnotationValue(),
|
||||||
method
|
method
|
||||||
);
|
);
|
||||||
|
|
||||||
FormattingParameters valueFormatting = new FormattingParameters(
|
FormattingParameters valueFormatting = new FormattingParameters(
|
||||||
prism.valueDateFormat(),
|
mapMapping.valueDateFormat().get(),
|
||||||
prism.valueNumberFormat(),
|
mapMapping.valueNumberFormat().get(),
|
||||||
prism.mirror,
|
mapMapping.mirror(),
|
||||||
prism.values.valueDateFormat(),
|
mapMapping.valueDateFormat().getAnnotationValue(),
|
||||||
method
|
method
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -73,24 +80,25 @@ public class MapMappingOptions extends DelegatingOptions {
|
|||||||
keySelection,
|
keySelection,
|
||||||
valueFormatting,
|
valueFormatting,
|
||||||
valueSelection,
|
valueSelection,
|
||||||
prism,
|
mapMapping,
|
||||||
mapperOptions
|
mapperOptions
|
||||||
);
|
);
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isConsistent(MapMappingPrism prism, ExecutableElement method, FormattingMessager messager) {
|
private static boolean isConsistent(MapMappingGem gem, ExecutableElement method,
|
||||||
if ( prism.keyDateFormat().isEmpty()
|
FormattingMessager messager) {
|
||||||
&& prism.keyNumberFormat().isEmpty()
|
if ( !gem.keyDateFormat().hasValue()
|
||||||
&& prism.keyQualifiedBy().isEmpty()
|
&& !gem.keyNumberFormat().hasValue()
|
||||||
&& prism.keyQualifiedByName().isEmpty()
|
&& !gem.keyQualifiedBy().hasValue()
|
||||||
&& prism.valueDateFormat().isEmpty()
|
&& !gem.keyQualifiedByName().hasValue()
|
||||||
&& prism.valueNumberFormat().isEmpty()
|
&& !gem.valueDateFormat().hasValue()
|
||||||
&& prism.valueQualifiedBy().isEmpty()
|
&& !gem.valueNumberFormat().hasValue()
|
||||||
&& prism.valueQualifiedByName().isEmpty()
|
&& !gem.valueQualifiedBy().hasValue()
|
||||||
&& TypeKind.VOID == prism.keyTargetType().getKind()
|
&& !gem.valueQualifiedByName().hasValue()
|
||||||
&& TypeKind.VOID == prism.valueTargetType().getKind()
|
&& !gem.keyTargetType().hasValue()
|
||||||
&& null == prism.values.nullValueMappingStrategy() ) {
|
&& !gem.valueTargetType().hasValue()
|
||||||
|
&& !gem.nullValueMappingStrategy().hasValue() ) {
|
||||||
messager.printMessage( method, Message.MAPMAPPING_NO_ELEMENTS );
|
messager.printMessage( method, Message.MAPMAPPING_NO_ELEMENTS );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -99,13 +107,13 @@ public class MapMappingOptions extends DelegatingOptions {
|
|||||||
|
|
||||||
private MapMappingOptions(FormattingParameters keyFormatting, SelectionParameters keySelectionParameters,
|
private MapMappingOptions(FormattingParameters keyFormatting, SelectionParameters keySelectionParameters,
|
||||||
FormattingParameters valueFormatting, SelectionParameters valueSelectionParameters,
|
FormattingParameters valueFormatting, SelectionParameters valueSelectionParameters,
|
||||||
MapMappingPrism prism, DelegatingOptions next ) {
|
MapMappingGem mapMapping, DelegatingOptions next ) {
|
||||||
super( next );
|
super( next );
|
||||||
this.keyFormattingParameters = keyFormatting;
|
this.keyFormattingParameters = keyFormatting;
|
||||||
this.keySelectionParameters = keySelectionParameters;
|
this.keySelectionParameters = keySelectionParameters;
|
||||||
this.valueFormattingParameters = valueFormatting;
|
this.valueFormattingParameters = valueFormatting;
|
||||||
this.valueSelectionParameters = valueSelectionParameters;
|
this.valueSelectionParameters = valueSelectionParameters;
|
||||||
this.prism = prism;
|
this.mapMapping = mapMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormattingParameters getKeyFormattingParameters() {
|
public FormattingParameters getKeyFormattingParameters() {
|
||||||
@ -125,19 +133,21 @@ public class MapMappingOptions extends DelegatingOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AnnotationMirror getMirror() {
|
public AnnotationMirror getMirror() {
|
||||||
return null == prism ? null : prism.mirror;
|
return Optional.ofNullable( mapMapping ).map( MapMappingGem::mirror ).orElse( null );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NullValueMappingStrategyPrism getNullValueMappingStrategy() {
|
public NullValueMappingStrategyGem getNullValueMappingStrategy() {
|
||||||
return null == prism || null == prism.values.nullValueMappingStrategy() ?
|
return Optional.ofNullable( mapMapping ).map( MapMappingGem::nullValueMappingStrategy )
|
||||||
next().getNullValueMappingStrategy()
|
.filter( GemValue::hasValue )
|
||||||
: NullValueMappingStrategyPrism.valueOf( prism.nullValueMappingStrategy() );
|
.map( GemValue::getValue )
|
||||||
|
.map( NullValueMappingStrategyGem::valueOf )
|
||||||
|
.orElse( next().getNullValueMappingStrategy() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasAnnotation() {
|
public boolean hasAnnotation() {
|
||||||
return prism != null;
|
return mapMapping != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,124 +8,130 @@ package org.mapstruct.ap.internal.model.source;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.lang.model.type.DeclaredType;
|
import javax.lang.model.type.DeclaredType;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.prism.BuilderPrism;
|
import org.mapstruct.ap.internal.gem.BuilderGem;
|
||||||
import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.InjectionStrategyPrism;
|
import org.mapstruct.ap.internal.gem.InjectionStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.MapperConfigPrism;
|
import org.mapstruct.ap.internal.gem.MapperConfigGem;
|
||||||
import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism;
|
import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.ReportingPolicyPrism;
|
import org.mapstruct.ap.internal.gem.ReportingPolicyGem;
|
||||||
|
|
||||||
public class MapperConfigOptions extends DelegatingOptions {
|
public class MapperConfigOptions extends DelegatingOptions {
|
||||||
|
|
||||||
private final MapperConfigPrism prism;
|
private final MapperConfigGem mapperConfig;
|
||||||
|
|
||||||
MapperConfigOptions(MapperConfigPrism prism, DelegatingOptions next ) {
|
MapperConfigOptions(MapperConfigGem mapperConfig, DelegatingOptions next ) {
|
||||||
super( next );
|
super( next );
|
||||||
this.prism = prism;
|
this.mapperConfig = mapperConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String implementationName() {
|
public String implementationName() {
|
||||||
return null == prism.values.implementationName() ? next().implementationName() :
|
return mapperConfig.implementationName().hasValue() ? mapperConfig.implementationName().get() :
|
||||||
prism.implementationName();
|
next().implementationName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String implementationPackage() {
|
public String implementationPackage() {
|
||||||
return null == prism.values.implementationPackage() ? next().implementationPackage() :
|
return mapperConfig.implementationPackage().hasValue() ? mapperConfig.implementationPackage().get() :
|
||||||
prism.implementationPackage();
|
next().implementationPackage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<DeclaredType> uses() {
|
public Set<DeclaredType> uses() {
|
||||||
return toDeclaredTypes( prism.uses(), next().uses() );
|
return toDeclaredTypes( mapperConfig.uses().get(), next().uses() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<DeclaredType> imports() {
|
public Set<DeclaredType> imports() {
|
||||||
return toDeclaredTypes( prism.imports(), next().imports() );
|
return toDeclaredTypes( mapperConfig.imports().get(), next().imports() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReportingPolicyPrism unmappedTargetPolicy() {
|
public ReportingPolicyGem unmappedTargetPolicy() {
|
||||||
return null == prism.values.unmappedTargetPolicy() ? next().unmappedTargetPolicy() :
|
return mapperConfig.unmappedTargetPolicy().hasValue() ?
|
||||||
ReportingPolicyPrism.valueOf( prism.unmappedTargetPolicy() );
|
ReportingPolicyGem.valueOf( mapperConfig.unmappedTargetPolicy().get() ) : next().unmappedTargetPolicy();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReportingPolicyPrism unmappedSourcePolicy() {
|
public ReportingPolicyGem unmappedSourcePolicy() {
|
||||||
return null == prism.values.unmappedSourcePolicy() ? next().unmappedSourcePolicy() :
|
return mapperConfig.unmappedSourcePolicy().hasValue() ?
|
||||||
ReportingPolicyPrism.valueOf( prism.unmappedSourcePolicy() );
|
ReportingPolicyGem.valueOf( mapperConfig.unmappedSourcePolicy().get() ) : next().unmappedSourcePolicy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReportingPolicyPrism typeConversionPolicy() {
|
public ReportingPolicyGem typeConversionPolicy() {
|
||||||
return null == prism.values.typeConversionPolicy() ? next().typeConversionPolicy() :
|
return mapperConfig.typeConversionPolicy().hasValue() ?
|
||||||
ReportingPolicyPrism.valueOf( prism.typeConversionPolicy() );
|
ReportingPolicyGem.valueOf( mapperConfig.typeConversionPolicy().get() ) : next().typeConversionPolicy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String componentModel() {
|
public String componentModel() {
|
||||||
return null == prism.values.componentModel() ? next().componentModel() : prism.componentModel();
|
return mapperConfig.componentModel().hasValue() ? mapperConfig.componentModel().get() : next().componentModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MappingInheritanceStrategyPrism getMappingInheritanceStrategy() {
|
public MappingInheritanceStrategyGem getMappingInheritanceStrategy() {
|
||||||
return null == prism.values.mappingInheritanceStrategy() ? next().getMappingInheritanceStrategy() :
|
return mapperConfig.mappingInheritanceStrategy().hasValue() ?
|
||||||
MappingInheritanceStrategyPrism.valueOf( prism.mappingInheritanceStrategy() );
|
MappingInheritanceStrategyGem.valueOf( mapperConfig.mappingInheritanceStrategy().get() ) :
|
||||||
|
next().getMappingInheritanceStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InjectionStrategyPrism getInjectionStrategy() {
|
public InjectionStrategyGem getInjectionStrategy() {
|
||||||
return null == prism.values.injectionStrategy() ? next().getInjectionStrategy() :
|
return mapperConfig.injectionStrategy().hasValue() ?
|
||||||
InjectionStrategyPrism.valueOf( prism.injectionStrategy() );
|
InjectionStrategyGem.valueOf( mapperConfig.injectionStrategy().get() ) :
|
||||||
|
next().getInjectionStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean isDisableSubMappingMethodsGeneration() {
|
public Boolean isDisableSubMappingMethodsGeneration() {
|
||||||
return null == prism.values.disableSubMappingMethodsGeneration() ?
|
return mapperConfig.disableSubMappingMethodsGeneration().hasValue() ?
|
||||||
next().isDisableSubMappingMethodsGeneration() : prism.disableSubMappingMethodsGeneration();
|
mapperConfig.disableSubMappingMethodsGeneration().get() :
|
||||||
|
next().isDisableSubMappingMethodsGeneration();
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Mapping, @BeanMapping
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionMappingStrategyGem getCollectionMappingStrategy() {
|
||||||
|
return mapperConfig.collectionMappingStrategy().hasValue() ?
|
||||||
|
CollectionMappingStrategyGem.valueOf( mapperConfig.collectionMappingStrategy().get() ) :
|
||||||
|
next().getCollectionMappingStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CollectionMappingStrategyPrism getCollectionMappingStrategy() {
|
public NullValueCheckStrategyGem getNullValueCheckStrategy() {
|
||||||
return null == prism.values.collectionMappingStrategy() ?
|
return mapperConfig.nullValueCheckStrategy().hasValue() ?
|
||||||
next().getCollectionMappingStrategy()
|
NullValueCheckStrategyGem.valueOf( mapperConfig.nullValueCheckStrategy().get() ) :
|
||||||
: CollectionMappingStrategyPrism.valueOf( prism.collectionMappingStrategy() );
|
next().getNullValueCheckStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NullValueCheckStrategyPrism getNullValueCheckStrategy() {
|
public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() {
|
||||||
return null == prism.values.nullValueCheckStrategy() ?
|
return mapperConfig.nullValuePropertyMappingStrategy().hasValue() ?
|
||||||
next().getNullValueCheckStrategy()
|
NullValuePropertyMappingStrategyGem.valueOf( mapperConfig.nullValuePropertyMappingStrategy().get() ) :
|
||||||
: NullValueCheckStrategyPrism.valueOf( prism.nullValueCheckStrategy() );
|
next().getNullValuePropertyMappingStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() {
|
public NullValueMappingStrategyGem getNullValueMappingStrategy() {
|
||||||
return null == prism.values.nullValuePropertyMappingStrategy() ?
|
return mapperConfig.nullValueMappingStrategy().hasValue() ?
|
||||||
next().getNullValuePropertyMappingStrategy()
|
NullValueMappingStrategyGem.valueOf( mapperConfig.nullValueMappingStrategy().get() ) :
|
||||||
: NullValuePropertyMappingStrategyPrism.valueOf( prism.nullValuePropertyMappingStrategy() );
|
next().getNullValueMappingStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NullValueMappingStrategyPrism getNullValueMappingStrategy() {
|
public BuilderGem getBuilder() {
|
||||||
return null == prism.values.nullValueMappingStrategy() ?
|
return mapperConfig.builder().hasValue() ? mapperConfig.builder().get() : next().getBuilder();
|
||||||
next().getNullValueMappingStrategy()
|
|
||||||
: NullValueMappingStrategyPrism.valueOf( prism.nullValueMappingStrategy() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BuilderPrism getBuilderPrism() {
|
|
||||||
return null == prism.values.builder() ? next().getBuilderPrism() : prism.builder();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasAnnotation() {
|
public boolean hasAnnotation() {
|
||||||
return prism != null;
|
return mapperConfig != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,146 +13,150 @@ import javax.lang.model.type.DeclaredType;
|
|||||||
import javax.lang.model.type.TypeKind;
|
import javax.lang.model.type.TypeKind;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.option.Options;
|
import org.mapstruct.ap.internal.option.Options;
|
||||||
import org.mapstruct.ap.internal.prism.BuilderPrism;
|
import org.mapstruct.ap.internal.gem.BuilderGem;
|
||||||
import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.InjectionStrategyPrism;
|
import org.mapstruct.ap.internal.gem.InjectionStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.MapperConfigPrism;
|
import org.mapstruct.ap.internal.gem.MapperConfigGem;
|
||||||
import org.mapstruct.ap.internal.prism.MapperPrism;
|
import org.mapstruct.ap.internal.gem.MapperGem;
|
||||||
import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism;
|
import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.ReportingPolicyPrism;
|
import org.mapstruct.ap.internal.gem.ReportingPolicyGem;
|
||||||
|
|
||||||
public class MapperOptions extends DelegatingOptions {
|
public class MapperOptions extends DelegatingOptions {
|
||||||
|
|
||||||
private final MapperPrism prism;
|
private final MapperGem mapper;
|
||||||
private final DeclaredType mapperConfigType;
|
private final DeclaredType mapperConfigType;
|
||||||
|
|
||||||
public static MapperOptions getInstanceOn(TypeElement typeElement, Options options) {
|
public static MapperOptions getInstanceOn(TypeElement typeElement, Options options) {
|
||||||
MapperPrism prism = MapperPrism.getInstanceOn( typeElement );
|
MapperGem mapper = MapperGem.instanceOn( typeElement );
|
||||||
MapperOptions mapperAnnotation;
|
MapperOptions mapperAnnotation;
|
||||||
DelegatingOptions defaults = new DefaultOptions( prism, options );
|
DelegatingOptions defaults = new DefaultOptions( mapper, options );
|
||||||
DeclaredType mapperConfigType;
|
DeclaredType mapperConfigType;
|
||||||
if ( prism.values.config() != null && prism.config().getKind() == TypeKind.DECLARED ) {
|
if ( mapper.config().hasValue() && mapper.config().getValue().getKind() == TypeKind.DECLARED ) {
|
||||||
mapperConfigType = (DeclaredType) prism.config();
|
mapperConfigType = (DeclaredType) mapper.config().get();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mapperConfigType = null;
|
mapperConfigType = null;
|
||||||
}
|
}
|
||||||
if ( mapperConfigType != null ) {
|
if ( mapperConfigType != null ) {
|
||||||
Element mapperConfigElement = mapperConfigType.asElement();
|
Element mapperConfigElement = mapperConfigType.asElement();
|
||||||
MapperConfigPrism configPrism = MapperConfigPrism.getInstanceOn( mapperConfigElement );
|
MapperConfigGem mapperConfig = MapperConfigGem.instanceOn( mapperConfigElement );
|
||||||
MapperConfigOptions mapperConfigAnnotation = new MapperConfigOptions( configPrism, defaults );
|
MapperConfigOptions mapperConfigAnnotation = new MapperConfigOptions( mapperConfig, defaults );
|
||||||
mapperAnnotation = new MapperOptions( prism, mapperConfigType, mapperConfigAnnotation );
|
mapperAnnotation = new MapperOptions( mapper, mapperConfigType, mapperConfigAnnotation );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mapperAnnotation = new MapperOptions( prism, null, defaults );
|
mapperAnnotation = new MapperOptions( mapper, null, defaults );
|
||||||
}
|
}
|
||||||
return mapperAnnotation;
|
return mapperAnnotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MapperOptions(MapperPrism prism, DeclaredType mapperConfigType, DelegatingOptions next) {
|
private MapperOptions(MapperGem mapper, DeclaredType mapperConfigType, DelegatingOptions next) {
|
||||||
super( next );
|
super( next );
|
||||||
this.prism = prism;
|
this.mapper = mapper;
|
||||||
this.mapperConfigType = mapperConfigType;
|
this.mapperConfigType = mapperConfigType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String implementationName() {
|
public String implementationName() {
|
||||||
return null == prism.values.implementationName() ? next().implementationName() : prism.implementationName();
|
return mapper.implementationName().hasValue() ? mapper.implementationName().get() : next().implementationName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String implementationPackage() {
|
public String implementationPackage() {
|
||||||
return null == prism.values.implementationPackage() ? next().implementationPackage() :
|
return mapper.implementationPackage().hasValue() ? mapper.implementationPackage().get() :
|
||||||
prism.implementationPackage();
|
next().implementationPackage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<DeclaredType> uses() {
|
public Set<DeclaredType> uses() {
|
||||||
return toDeclaredTypes( prism.uses(), next().uses() );
|
return toDeclaredTypes( mapper.uses().get(), next().uses() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<DeclaredType> imports() {
|
public Set<DeclaredType> imports() {
|
||||||
return toDeclaredTypes( prism.imports(), next().imports() );
|
return toDeclaredTypes( mapper.imports().get(), next().imports() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReportingPolicyPrism unmappedTargetPolicy() {
|
public ReportingPolicyGem unmappedTargetPolicy() {
|
||||||
return null == prism.values.unmappedTargetPolicy() ? next().unmappedTargetPolicy() :
|
return mapper.unmappedTargetPolicy().hasValue() ?
|
||||||
ReportingPolicyPrism.valueOf( prism.unmappedTargetPolicy() );
|
ReportingPolicyGem.valueOf( mapper.unmappedTargetPolicy().get() ) : next().unmappedTargetPolicy();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReportingPolicyPrism unmappedSourcePolicy() {
|
public ReportingPolicyGem unmappedSourcePolicy() {
|
||||||
return null == prism.values.unmappedSourcePolicy() ? next().unmappedSourcePolicy() :
|
return mapper.unmappedSourcePolicy().hasValue() ?
|
||||||
ReportingPolicyPrism.valueOf( prism.unmappedSourcePolicy() );
|
ReportingPolicyGem.valueOf( mapper.unmappedSourcePolicy().get() ) : next().unmappedSourcePolicy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReportingPolicyPrism typeConversionPolicy() {
|
public ReportingPolicyGem typeConversionPolicy() {
|
||||||
return null == prism.values.typeConversionPolicy() ? next().typeConversionPolicy() :
|
return mapper.typeConversionPolicy().hasValue() ?
|
||||||
ReportingPolicyPrism.valueOf( prism.typeConversionPolicy() );
|
ReportingPolicyGem.valueOf( mapper.typeConversionPolicy().get() ) : next().typeConversionPolicy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String componentModel() {
|
public String componentModel() {
|
||||||
return null == prism.values.componentModel() ? next().componentModel() : prism.componentModel();
|
return mapper.componentModel().hasValue() ? mapper.componentModel().get() : next().componentModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MappingInheritanceStrategyPrism getMappingInheritanceStrategy() {
|
public MappingInheritanceStrategyGem getMappingInheritanceStrategy() {
|
||||||
return null == prism.values.mappingInheritanceStrategy() ? next().getMappingInheritanceStrategy() :
|
return mapper.mappingInheritanceStrategy().hasValue() ?
|
||||||
MappingInheritanceStrategyPrism.valueOf( prism.mappingInheritanceStrategy() );
|
MappingInheritanceStrategyGem.valueOf( mapper.mappingInheritanceStrategy().get() ) :
|
||||||
|
next().getMappingInheritanceStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InjectionStrategyPrism getInjectionStrategy() {
|
public InjectionStrategyGem getInjectionStrategy() {
|
||||||
return null == prism.values.injectionStrategy() ? next().getInjectionStrategy() :
|
return mapper.injectionStrategy().hasValue() ?
|
||||||
InjectionStrategyPrism.valueOf( prism.injectionStrategy() );
|
InjectionStrategyGem.valueOf( mapper.injectionStrategy().get() ) :
|
||||||
|
next().getInjectionStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean isDisableSubMappingMethodsGeneration() {
|
public Boolean isDisableSubMappingMethodsGeneration() {
|
||||||
return null == prism.values.disableSubMappingMethodsGeneration() ?
|
return mapper.disableSubMappingMethodsGeneration().hasValue() ?
|
||||||
next().isDisableSubMappingMethodsGeneration() : prism.disableSubMappingMethodsGeneration();
|
mapper.disableSubMappingMethodsGeneration().get() :
|
||||||
|
next().isDisableSubMappingMethodsGeneration();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Mapping, @BeanMapping
|
// @Mapping, @BeanMapping
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CollectionMappingStrategyPrism getCollectionMappingStrategy() {
|
public CollectionMappingStrategyGem getCollectionMappingStrategy() {
|
||||||
return null == prism.values.collectionMappingStrategy() ?
|
return mapper.collectionMappingStrategy().hasValue() ?
|
||||||
next().getCollectionMappingStrategy()
|
CollectionMappingStrategyGem.valueOf( mapper.collectionMappingStrategy().get() ) :
|
||||||
: CollectionMappingStrategyPrism.valueOf( prism.collectionMappingStrategy() );
|
next().getCollectionMappingStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NullValueCheckStrategyPrism getNullValueCheckStrategy() {
|
public NullValueCheckStrategyGem getNullValueCheckStrategy() {
|
||||||
return null == prism.values.nullValueCheckStrategy() ?
|
return mapper.nullValueCheckStrategy().hasValue() ?
|
||||||
next().getNullValueCheckStrategy()
|
NullValueCheckStrategyGem.valueOf( mapper.nullValueCheckStrategy().get() ) :
|
||||||
: NullValueCheckStrategyPrism.valueOf( prism.nullValueCheckStrategy() );
|
next().getNullValueCheckStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() {
|
public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() {
|
||||||
return null == prism.values.nullValuePropertyMappingStrategy() ?
|
return mapper.nullValuePropertyMappingStrategy().hasValue() ?
|
||||||
next().getNullValuePropertyMappingStrategy()
|
NullValuePropertyMappingStrategyGem.valueOf( mapper.nullValuePropertyMappingStrategy().get() ) :
|
||||||
: NullValuePropertyMappingStrategyPrism.valueOf( prism.nullValuePropertyMappingStrategy() );
|
next().getNullValuePropertyMappingStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NullValueMappingStrategyPrism getNullValueMappingStrategy() {
|
public NullValueMappingStrategyGem getNullValueMappingStrategy() {
|
||||||
return null == prism.values.nullValueMappingStrategy() ?
|
return mapper.nullValueMappingStrategy().hasValue() ?
|
||||||
next().getNullValueMappingStrategy()
|
NullValueMappingStrategyGem.valueOf( mapper.nullValueMappingStrategy().get() ) :
|
||||||
: NullValueMappingStrategyPrism.valueOf( prism.nullValueMappingStrategy() );
|
next().getNullValueMappingStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BuilderPrism getBuilderPrism() {
|
public BuilderGem getBuilder() {
|
||||||
return null == prism.values.builder() ? next().getBuilderPrism() : prism.builder();
|
return mapper.builder().hasValue() ? mapper.builder().get() : next().getBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Mapper specific
|
// @Mapper specific
|
||||||
@ -166,11 +170,11 @@ public class MapperOptions extends DelegatingOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
return prism.isValid;
|
return mapper.isValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnnotationMirror getAnnotationMirror() {
|
public AnnotationMirror getAnnotationMirror() {
|
||||||
return prism.mirror;
|
return mapper.mirror();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,7 +14,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import org.mapstruct.ap.internal.model.common.Type;
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
||||||
import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.util.accessor.Accessor;
|
import org.mapstruct.ap.internal.util.accessor.Accessor;
|
||||||
|
|
||||||
import static org.mapstruct.ap.internal.model.source.MappingOptions.getMappingTargetNamesBy;
|
import static org.mapstruct.ap.internal.model.source.MappingOptions.getMappingTargetNamesBy;
|
||||||
@ -185,12 +185,12 @@ public class MappingMethodOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void applyIgnoreAll(SourceMethod method, TypeFactory typeFactory ) {
|
public void applyIgnoreAll(SourceMethod method, TypeFactory typeFactory ) {
|
||||||
CollectionMappingStrategyPrism cms = method.getOptions().getMapper().getCollectionMappingStrategy();
|
CollectionMappingStrategyGem cms = method.getOptions().getMapper().getCollectionMappingStrategy();
|
||||||
Type writeType = method.getResultType();
|
Type writeType = method.getResultType();
|
||||||
if ( !method.isUpdateMethod() ) {
|
if ( !method.isUpdateMethod() ) {
|
||||||
writeType = typeFactory.effectiveResultTypeFor(
|
writeType = typeFactory.effectiveResultTypeFor(
|
||||||
writeType,
|
writeType,
|
||||||
method.getOptions().getBeanMapping().getBuilderPrism()
|
method.getOptions().getBeanMapping().getBuilder()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Map<String, Accessor> writeAccessors = writeType.getPropertyWriteAccessors( cms );
|
Map<String, Accessor> writeAccessors = writeType.getPropertyWriteAccessors( cms );
|
||||||
|
@ -8,6 +8,7 @@ package org.mapstruct.ap.internal.model.source;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@ -19,12 +20,13 @@ import javax.lang.model.element.ExecutableElement;
|
|||||||
import javax.lang.model.util.Types;
|
import javax.lang.model.util.Types;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.model.common.FormattingParameters;
|
import org.mapstruct.ap.internal.model.common.FormattingParameters;
|
||||||
import org.mapstruct.ap.internal.prism.MappingPrism;
|
import org.mapstruct.ap.internal.gem.MappingGem;
|
||||||
import org.mapstruct.ap.internal.prism.MappingsPrism;
|
import org.mapstruct.ap.internal.gem.MappingsGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.util.FormattingMessager;
|
import org.mapstruct.ap.internal.util.FormattingMessager;
|
||||||
import org.mapstruct.ap.internal.util.Message;
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
|
import org.mapstruct.tools.gem.GemValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a property mapping as configured via {@code @Mapping} (no intermediate state).
|
* Represents a property mapping as configured via {@code @Mapping} (no intermediate state).
|
||||||
@ -49,7 +51,7 @@ public class MappingOptions extends DelegatingOptions {
|
|||||||
|
|
||||||
private final AnnotationValue sourceAnnotationValue;
|
private final AnnotationValue sourceAnnotationValue;
|
||||||
private final AnnotationValue targetAnnotationValue;
|
private final AnnotationValue targetAnnotationValue;
|
||||||
private final MappingPrism prism;
|
private final MappingGem mapping;
|
||||||
|
|
||||||
private final InheritContext inheritContext;
|
private final InheritContext inheritContext;
|
||||||
|
|
||||||
@ -86,70 +88,70 @@ public class MappingOptions extends DelegatingOptions {
|
|||||||
.collect( Collectors.toCollection( LinkedHashSet::new ) );
|
.collect( Collectors.toCollection( LinkedHashSet::new ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addInstances(MappingsPrism prism, ExecutableElement method,
|
public static void addInstances(MappingsGem gem, ExecutableElement method,
|
||||||
BeanMappingOptions beanMappingOptions,
|
BeanMappingOptions beanMappingOptions,
|
||||||
FormattingMessager messager, Types typeUtils,
|
FormattingMessager messager, Types typeUtils,
|
||||||
Set<MappingOptions> mappings) {
|
Set<MappingOptions> mappings) {
|
||||||
|
|
||||||
for ( MappingPrism mappingPrism : prism.value() ) {
|
for ( MappingGem mapping : gem.value().getValue() ) {
|
||||||
addInstance( mappingPrism, method, beanMappingOptions, messager, typeUtils, mappings );
|
addInstance( mapping, method, beanMappingOptions, messager, typeUtils, mappings );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addInstance(MappingPrism prism, ExecutableElement method, BeanMappingOptions beanMappingOptions,
|
public static void addInstance(MappingGem mapping, ExecutableElement method,
|
||||||
FormattingMessager messager, Types typeUtils, Set<MappingOptions> mappings) {
|
BeanMappingOptions beanMappingOptions, FormattingMessager messager, Types typeUtils,
|
||||||
|
Set<MappingOptions> mappings) {
|
||||||
|
|
||||||
if ( !isConsistent( prism, method, messager ) ) {
|
if ( !isConsistent( mapping, method, messager ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String source = prism.source().isEmpty() ? null : prism.source();
|
String source = mapping.source().getValue();
|
||||||
String constant = prism.values.constant() == null ? null : prism.constant();
|
String constant = mapping.constant().getValue();
|
||||||
String expression = getExpression( prism, method, messager );
|
String expression = getExpression( mapping, method, messager );
|
||||||
String defaultExpression = getDefaultExpression( prism, method, messager );
|
String defaultExpression = getDefaultExpression( mapping, method, messager );
|
||||||
String dateFormat = prism.values.dateFormat() == null ? null : prism.dateFormat();
|
String dateFormat = mapping.dateFormat().getValue();
|
||||||
String numberFormat = prism.values.numberFormat() == null ? null : prism.numberFormat();
|
String numberFormat = mapping.numberFormat().getValue();
|
||||||
String defaultValue = prism.values.defaultValue() == null ? null : prism.defaultValue();
|
String defaultValue = mapping.defaultValue().getValue();
|
||||||
|
|
||||||
boolean resultTypeIsDefined = prism.values.resultType() != null;
|
Set<String> dependsOn = mapping.dependsOn().hasValue() ?
|
||||||
Set<String> dependsOn = prism.dependsOn() != null ?
|
new LinkedHashSet( mapping.dependsOn().getValue() ) :
|
||||||
new LinkedHashSet( prism.dependsOn() ) :
|
|
||||||
Collections.emptySet();
|
Collections.emptySet();
|
||||||
|
|
||||||
FormattingParameters formattingParam = new FormattingParameters(
|
FormattingParameters formattingParam = new FormattingParameters(
|
||||||
dateFormat,
|
dateFormat,
|
||||||
numberFormat,
|
numberFormat,
|
||||||
prism.mirror,
|
mapping.mirror(),
|
||||||
prism.values.dateFormat(),
|
mapping.dateFormat().getAnnotationValue(),
|
||||||
method
|
method
|
||||||
);
|
);
|
||||||
SelectionParameters selectionParams = new SelectionParameters(
|
SelectionParameters selectionParams = new SelectionParameters(
|
||||||
prism.qualifiedBy(),
|
mapping.qualifiedBy().get(),
|
||||||
prism.qualifiedByName(),
|
mapping.qualifiedByName().get(),
|
||||||
resultTypeIsDefined ? prism.resultType() : null,
|
mapping.resultType().getValue(),
|
||||||
typeUtils
|
typeUtils
|
||||||
);
|
);
|
||||||
|
|
||||||
MappingOptions options = new MappingOptions(
|
MappingOptions options = new MappingOptions(
|
||||||
prism.target(),
|
mapping.target().getValue(),
|
||||||
prism.values.target(),
|
mapping.target().getAnnotationValue(),
|
||||||
source,
|
source,
|
||||||
prism.values.source(),
|
mapping.source().getAnnotationValue(),
|
||||||
constant,
|
constant,
|
||||||
expression,
|
expression,
|
||||||
defaultExpression,
|
defaultExpression,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
prism.ignore(),
|
mapping.ignore().get(),
|
||||||
formattingParam,
|
formattingParam,
|
||||||
selectionParams,
|
selectionParams,
|
||||||
dependsOn,
|
dependsOn,
|
||||||
prism,
|
mapping,
|
||||||
null,
|
null,
|
||||||
beanMappingOptions
|
beanMappingOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( mappings.contains( options ) ) {
|
if ( mappings.contains( options ) ) {
|
||||||
messager.printMessage( method, Message.PROPERTYMAPPING_DUPLICATE_TARGETS, prism.target() );
|
messager.printMessage( method, Message.PROPERTYMAPPING_DUPLICATE_TARGETS, mapping.target().get() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mappings.add( options );
|
mappings.add( options );
|
||||||
@ -176,66 +178,62 @@ public class MappingOptions extends DelegatingOptions {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isConsistent(MappingPrism prism, ExecutableElement method,
|
private static boolean isConsistent(MappingGem gem, ExecutableElement method,
|
||||||
FormattingMessager messager) {
|
FormattingMessager messager) {
|
||||||
|
|
||||||
if ( prism.target().isEmpty() ) {
|
if ( !gem.target().hasValue() ) {
|
||||||
messager.printMessage(
|
messager.printMessage(
|
||||||
method,
|
method,
|
||||||
prism.mirror,
|
gem.mirror(),
|
||||||
prism.values.target(),
|
gem.target().getAnnotationValue(),
|
||||||
Message.PROPERTYMAPPING_EMPTY_TARGET
|
Message.PROPERTYMAPPING_EMPTY_TARGET
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Message message = null;
|
Message message = null;
|
||||||
if ( !prism.source().isEmpty() && prism.values.constant() != null ) {
|
if ( gem.source().hasValue() && gem.constant().hasValue() ) {
|
||||||
message = Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED;
|
message = Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED;
|
||||||
}
|
}
|
||||||
else if ( !prism.source().isEmpty() && prism.values.expression() != null ) {
|
else if ( gem.source().hasValue() && gem.expression().hasValue() ) {
|
||||||
message = Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED;
|
message = Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED;
|
||||||
}
|
}
|
||||||
else if ( prism.values.expression() != null && prism.values.constant() != null ) {
|
else if (gem.expression().hasValue() && gem.constant().hasValue() ) {
|
||||||
message = Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED;
|
message = Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED;
|
||||||
}
|
}
|
||||||
else if ( prism.values.expression() != null && prism.values.defaultValue() != null ) {
|
else if ( gem.expression().hasValue() && gem.defaultValue().hasValue() ) {
|
||||||
message = Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED;
|
message = Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED;
|
||||||
}
|
}
|
||||||
else if ( prism.values.constant() != null && prism.values.defaultValue() != null ) {
|
else if ( gem.constant().hasValue() && gem.defaultValue().hasValue() ) {
|
||||||
message = Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED;
|
message = Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED;
|
||||||
}
|
}
|
||||||
else if ( prism.values.expression() != null && prism.values.defaultExpression() != null ) {
|
else if ( gem.expression().hasValue() && gem.defaultExpression().hasValue() ) {
|
||||||
message = Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED;
|
message = Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED;
|
||||||
}
|
}
|
||||||
else if ( prism.values.constant() != null && prism.values.defaultExpression() != null ) {
|
else if ( gem.constant().hasValue() && gem.defaultExpression().hasValue() ) {
|
||||||
message = Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED;
|
message = Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED;
|
||||||
}
|
}
|
||||||
else if ( prism.values.defaultValue() != null && prism.values.defaultExpression() != null ) {
|
else if ( gem.defaultValue().hasValue() && gem.defaultExpression().hasValue() ) {
|
||||||
message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED;
|
message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED;
|
||||||
}
|
}
|
||||||
else if ( prism.values.expression() != null
|
else if ( gem.expression().hasValue()
|
||||||
&& ( prism.values.qualifiedByName() != null || prism.values.qualifiedBy() != null ) ) {
|
&& ( gem.qualifiedByName().hasValue() || gem.qualifiedBy().hasValue() ) ) {
|
||||||
message = Message.PROPERTYMAPPING_EXPRESSION_AND_QUALIFIER_BOTH_DEFINED;
|
message = Message.PROPERTYMAPPING_EXPRESSION_AND_QUALIFIER_BOTH_DEFINED;
|
||||||
}
|
}
|
||||||
else if ( prism.values.nullValuePropertyMappingStrategy() != null
|
else if ( gem.nullValuePropertyMappingStrategy().hasValue() && gem.defaultValue().hasValue() ) {
|
||||||
&& prism.values.defaultValue() != null ) {
|
|
||||||
message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_NVPMS;
|
message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_NVPMS;
|
||||||
}
|
}
|
||||||
else if ( prism.values.nullValuePropertyMappingStrategy() != null
|
else if ( gem.nullValuePropertyMappingStrategy().hasValue() && gem.constant().hasValue() ) {
|
||||||
&& prism.values.constant() != null ) {
|
|
||||||
message = Message.PROPERTYMAPPING_CONSTANT_VALUE_AND_NVPMS;
|
message = Message.PROPERTYMAPPING_CONSTANT_VALUE_AND_NVPMS;
|
||||||
}
|
}
|
||||||
else if ( prism.values.nullValuePropertyMappingStrategy() != null
|
else if ( gem.nullValuePropertyMappingStrategy().hasValue() && gem.expression().hasValue() ) {
|
||||||
&& prism.values.expression() != null ) {
|
|
||||||
message = Message.PROPERTYMAPPING_EXPRESSION_VALUE_AND_NVPMS;
|
message = Message.PROPERTYMAPPING_EXPRESSION_VALUE_AND_NVPMS;
|
||||||
}
|
}
|
||||||
else if ( prism.values.nullValuePropertyMappingStrategy() != null
|
else if ( gem.nullValuePropertyMappingStrategy().hasValue() && gem.defaultExpression().hasValue() ) {
|
||||||
&& prism.values.defaultExpression() != null ) {
|
|
||||||
message = Message.PROPERTYMAPPING_DEFAULT_EXPERSSION_AND_NVPMS;
|
message = Message.PROPERTYMAPPING_DEFAULT_EXPERSSION_AND_NVPMS;
|
||||||
}
|
}
|
||||||
else if ( prism.values.nullValuePropertyMappingStrategy() != null
|
else if ( gem.nullValuePropertyMappingStrategy().hasValue()
|
||||||
&& prism.ignore() != null && prism.ignore() ) {
|
&& gem.ignore().hasValue() && gem.ignore().getValue() ) {
|
||||||
message = Message.PROPERTYMAPPING_IGNORE_AND_NVPMS;
|
message = Message.PROPERTYMAPPING_IGNORE_AND_NVPMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +241,7 @@ public class MappingOptions extends DelegatingOptions {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
messager.printMessage( method, prism.mirror, message );
|
messager.printMessage( method, gem.mirror(), message );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,7 +259,7 @@ public class MappingOptions extends DelegatingOptions {
|
|||||||
FormattingParameters formattingParameters,
|
FormattingParameters formattingParameters,
|
||||||
SelectionParameters selectionParameters,
|
SelectionParameters selectionParameters,
|
||||||
Set<String> dependsOn,
|
Set<String> dependsOn,
|
||||||
MappingPrism prism,
|
MappingGem mapping,
|
||||||
InheritContext inheritContext,
|
InheritContext inheritContext,
|
||||||
DelegatingOptions next
|
DelegatingOptions next
|
||||||
) {
|
) {
|
||||||
@ -278,21 +276,23 @@ public class MappingOptions extends DelegatingOptions {
|
|||||||
this.formattingParameters = formattingParameters;
|
this.formattingParameters = formattingParameters;
|
||||||
this.selectionParameters = selectionParameters;
|
this.selectionParameters = selectionParameters;
|
||||||
this.dependsOn = dependsOn;
|
this.dependsOn = dependsOn;
|
||||||
this.prism = prism;
|
this.mapping = mapping;
|
||||||
this.inheritContext = inheritContext;
|
this.inheritContext = inheritContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getExpression(MappingPrism mappingPrism, ExecutableElement element,
|
private static String getExpression(MappingGem mapping, ExecutableElement element,
|
||||||
FormattingMessager messager) {
|
FormattingMessager messager) {
|
||||||
if ( mappingPrism.expression().isEmpty() ) {
|
if ( !mapping.expression().hasValue() ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( mappingPrism.expression() );
|
Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( mapping.expression().get() );
|
||||||
|
|
||||||
if ( !javaExpressionMatcher.matches() ) {
|
if ( !javaExpressionMatcher.matches() ) {
|
||||||
messager.printMessage(
|
messager.printMessage(
|
||||||
element, mappingPrism.mirror, mappingPrism.values.expression(),
|
element,
|
||||||
|
mapping.mirror(),
|
||||||
|
mapping.expression().getAnnotationValue(),
|
||||||
Message.PROPERTYMAPPING_INVALID_EXPRESSION
|
Message.PROPERTYMAPPING_INVALID_EXPRESSION
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
@ -301,17 +301,19 @@ public class MappingOptions extends DelegatingOptions {
|
|||||||
return javaExpressionMatcher.group( 1 ).trim();
|
return javaExpressionMatcher.group( 1 ).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getDefaultExpression(MappingPrism mappingPrism, ExecutableElement element,
|
private static String getDefaultExpression(MappingGem mapping, ExecutableElement element,
|
||||||
FormattingMessager messager) {
|
FormattingMessager messager) {
|
||||||
if ( mappingPrism.defaultExpression().isEmpty() ) {
|
if ( !mapping.defaultExpression().hasValue() ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( mappingPrism.defaultExpression() );
|
Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( mapping.defaultExpression().get() );
|
||||||
|
|
||||||
if ( !javaExpressionMatcher.matches() ) {
|
if ( !javaExpressionMatcher.matches() ) {
|
||||||
messager.printMessage(
|
messager.printMessage(
|
||||||
element, mappingPrism.mirror, mappingPrism.values.defaultExpression(),
|
element,
|
||||||
|
mapping.mirror(),
|
||||||
|
mapping.defaultExpression().getAnnotationValue(),
|
||||||
Message.PROPERTYMAPPING_INVALID_DEFAULT_EXPRESSION
|
Message.PROPERTYMAPPING_INVALID_DEFAULT_EXPRESSION
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
@ -371,11 +373,14 @@ public class MappingOptions extends DelegatingOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AnnotationMirror getMirror() {
|
public AnnotationMirror getMirror() {
|
||||||
return prism == null ? null : prism.mirror;
|
return Optional.ofNullable( mapping ).map( MappingGem::mirror ).orElse( null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnnotationValue getDependsOnAnnotationValue() {
|
public AnnotationValue getDependsOnAnnotationValue() {
|
||||||
return prism == null ? null : prism.values.dependsOn();
|
return Optional.ofNullable( mapping )
|
||||||
|
.map( MappingGem::dependsOn )
|
||||||
|
.map( GemValue::getAnnotationValue )
|
||||||
|
.orElse( null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getDependsOn() {
|
public Set<String> getDependsOn() {
|
||||||
@ -387,17 +392,21 @@ public class MappingOptions extends DelegatingOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NullValueCheckStrategyPrism getNullValueCheckStrategy() {
|
public NullValueCheckStrategyGem getNullValueCheckStrategy() {
|
||||||
return null == prism || null == prism.values.nullValueCheckStrategy() ?
|
return Optional.ofNullable( mapping ).map( MappingGem::nullValueCheckStrategy )
|
||||||
next().getNullValueCheckStrategy()
|
.filter( GemValue::hasValue )
|
||||||
: NullValueCheckStrategyPrism.valueOf( prism.nullValueCheckStrategy() );
|
.map( GemValue::getValue )
|
||||||
|
.map( NullValueCheckStrategyGem::valueOf )
|
||||||
|
.orElse( next().getNullValueCheckStrategy() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() {
|
public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() {
|
||||||
return null == prism || null == prism.values.nullValuePropertyMappingStrategy() ?
|
return Optional.ofNullable( mapping ).map( MappingGem::nullValuePropertyMappingStrategy )
|
||||||
next().getNullValuePropertyMappingStrategy()
|
.filter( GemValue::hasValue )
|
||||||
: NullValuePropertyMappingStrategyPrism.valueOf( prism.nullValuePropertyMappingStrategy() );
|
.map( GemValue::getValue )
|
||||||
|
.map( NullValuePropertyMappingStrategyGem::valueOf )
|
||||||
|
.orElse( next().getNullValuePropertyMappingStrategy() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -426,7 +435,7 @@ public class MappingOptions extends DelegatingOptions {
|
|||||||
formattingParameters,
|
formattingParameters,
|
||||||
selectionParameters,
|
selectionParameters,
|
||||||
Collections.emptySet(),
|
Collections.emptySet(),
|
||||||
prism,
|
mapping,
|
||||||
new InheritContext( true, false, templateMethod ),
|
new InheritContext( true, false, templateMethod ),
|
||||||
beanMappingOptions
|
beanMappingOptions
|
||||||
);
|
);
|
||||||
@ -454,7 +463,7 @@ public class MappingOptions extends DelegatingOptions {
|
|||||||
formattingParameters,
|
formattingParameters,
|
||||||
selectionParameters,
|
selectionParameters,
|
||||||
dependsOn,
|
dependsOn,
|
||||||
prism,
|
mapping,
|
||||||
new InheritContext( false, true, templateMethod ),
|
new InheritContext( false, true, templateMethod ),
|
||||||
beanMappingOptions
|
beanMappingOptions
|
||||||
);
|
);
|
||||||
@ -492,7 +501,7 @@ public class MappingOptions extends DelegatingOptions {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasAnnotation() {
|
public boolean hasAnnotation() {
|
||||||
return prism != null;
|
return mapping != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import org.mapstruct.ap.internal.model.common.Accessibility;
|
|||||||
import org.mapstruct.ap.internal.model.common.Parameter;
|
import org.mapstruct.ap.internal.model.common.Parameter;
|
||||||
import org.mapstruct.ap.internal.model.common.Type;
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
||||||
import org.mapstruct.ap.internal.prism.ObjectFactoryPrism;
|
import org.mapstruct.ap.internal.gem.ObjectFactoryGem;
|
||||||
import org.mapstruct.ap.internal.util.Executables;
|
import org.mapstruct.ap.internal.util.Executables;
|
||||||
import org.mapstruct.ap.internal.util.Strings;
|
import org.mapstruct.ap.internal.util.Strings;
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ public class SourceMethod implements Method {
|
|||||||
|
|
||||||
this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters );
|
this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters );
|
||||||
this.targetTypeParameter = Parameter.getTargetTypeParameter( parameters );
|
this.targetTypeParameter = Parameter.getTargetTypeParameter( parameters );
|
||||||
this.hasObjectFactoryAnnotation = ObjectFactoryPrism.getInstanceOn( executable ) != null;
|
this.hasObjectFactoryAnnotation = ObjectFactoryGem.instanceOn( executable ) != null;
|
||||||
this.isObjectFactory = determineIfIsObjectFactory();
|
this.isObjectFactory = determineIfIsObjectFactory();
|
||||||
|
|
||||||
this.typeUtils = builder.typeUtils;
|
this.typeUtils = builder.typeUtils;
|
||||||
|
@ -11,13 +11,13 @@ import javax.lang.model.element.AnnotationMirror;
|
|||||||
import javax.lang.model.element.AnnotationValue;
|
import javax.lang.model.element.AnnotationValue;
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.prism.ValueMappingPrism;
|
import org.mapstruct.ap.internal.gem.ValueMappingGem;
|
||||||
import org.mapstruct.ap.internal.prism.ValueMappingsPrism;
|
import org.mapstruct.ap.internal.gem.ValueMappingsGem;
|
||||||
import org.mapstruct.ap.internal.util.FormattingMessager;
|
import org.mapstruct.ap.internal.util.FormattingMessager;
|
||||||
import org.mapstruct.ap.internal.util.Message;
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
|
|
||||||
import static org.mapstruct.ap.internal.prism.MappingConstantsPrism.ANY_REMAINING;
|
import static org.mapstruct.ap.internal.gem.MappingConstantsGem.ANY_REMAINING;
|
||||||
import static org.mapstruct.ap.internal.prism.MappingConstantsPrism.ANY_UNMAPPED;
|
import static org.mapstruct.ap.internal.gem.MappingConstantsGem.ANY_UNMAPPED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the mapping between one value constant and another.
|
* Represents the mapping between one value constant and another.
|
||||||
@ -32,12 +32,12 @@ public class ValueMappingOptions {
|
|||||||
private final AnnotationValue sourceAnnotationValue;
|
private final AnnotationValue sourceAnnotationValue;
|
||||||
private final AnnotationValue targetAnnotationValue;
|
private final AnnotationValue targetAnnotationValue;
|
||||||
|
|
||||||
public static void fromMappingsPrism(ValueMappingsPrism mappingsAnnotation, ExecutableElement method,
|
public static void fromMappingsGem(ValueMappingsGem mappingsGem, ExecutableElement method,
|
||||||
FormattingMessager messager, List<ValueMappingOptions> mappings) {
|
FormattingMessager messager, List<ValueMappingOptions> mappings) {
|
||||||
|
|
||||||
boolean anyFound = false;
|
boolean anyFound = false;
|
||||||
for ( ValueMappingPrism mappingPrism : mappingsAnnotation.value() ) {
|
for ( ValueMappingGem mappingGem : mappingsGem.value().get() ) {
|
||||||
ValueMappingOptions mapping = fromMappingPrism( mappingPrism );
|
ValueMappingOptions mapping = fromMappingGem( mappingGem );
|
||||||
if ( mapping != null ) {
|
if ( mapping != null ) {
|
||||||
|
|
||||||
if ( !mappings.contains( mapping ) ) {
|
if ( !mappings.contains( mapping ) ) {
|
||||||
@ -46,10 +46,10 @@ public class ValueMappingOptions {
|
|||||||
else {
|
else {
|
||||||
messager.printMessage(
|
messager.printMessage(
|
||||||
method,
|
method,
|
||||||
mappingPrism.mirror,
|
mappingGem.mirror(),
|
||||||
mappingPrism.values.target(),
|
mappingGem.target().getAnnotationValue(),
|
||||||
Message.VALUEMAPPING_DUPLICATE_SOURCE,
|
Message.VALUEMAPPING_DUPLICATE_SOURCE,
|
||||||
mappingPrism.source()
|
mappingGem.source().get()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ( ANY_REMAINING.equals( mapping.source )
|
if ( ANY_REMAINING.equals( mapping.source )
|
||||||
@ -57,10 +57,10 @@ public class ValueMappingOptions {
|
|||||||
if ( anyFound ) {
|
if ( anyFound ) {
|
||||||
messager.printMessage(
|
messager.printMessage(
|
||||||
method,
|
method,
|
||||||
mappingPrism.mirror,
|
mappingGem.mirror(),
|
||||||
mappingPrism.values.target(),
|
mappingGem.target().getAnnotationValue(),
|
||||||
Message.VALUEMAPPING_ANY_AREADY_DEFINED,
|
Message.VALUEMAPPING_ANY_AREADY_DEFINED,
|
||||||
mappingPrism.source()
|
mappingGem.source().get()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
anyFound = true;
|
anyFound = true;
|
||||||
@ -69,10 +69,10 @@ public class ValueMappingOptions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ValueMappingOptions fromMappingPrism(ValueMappingPrism mappingPrism ) {
|
public static ValueMappingOptions fromMappingGem(ValueMappingGem mapping ) {
|
||||||
|
|
||||||
return new ValueMappingOptions( mappingPrism.source(), mappingPrism.target(), mappingPrism.mirror,
|
return new ValueMappingOptions( mapping.source().get(), mapping.target().get(), mapping.mirror(),
|
||||||
mappingPrism.values.source(), mappingPrism.values.target() );
|
mapping.source().getAnnotationValue(), mapping.target().getAnnotationValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValueMappingOptions(String source, String target, AnnotationMirror mirror,
|
private ValueMappingOptions(String source, String target, AnnotationMirror mirror,
|
||||||
|
@ -9,7 +9,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.lang.model.element.AnnotationMirror;
|
import javax.lang.model.element.AnnotationMirror;
|
||||||
import javax.lang.model.type.DeclaredType;
|
import javax.lang.model.type.DeclaredType;
|
||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
@ -19,8 +18,8 @@ import javax.lang.model.util.Types;
|
|||||||
import org.mapstruct.ap.internal.model.common.Type;
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
import org.mapstruct.ap.internal.model.source.Method;
|
import org.mapstruct.ap.internal.model.source.Method;
|
||||||
import org.mapstruct.ap.internal.model.source.SourceMethod;
|
import org.mapstruct.ap.internal.model.source.SourceMethod;
|
||||||
import org.mapstruct.ap.internal.prism.NamedPrism;
|
import org.mapstruct.ap.internal.gem.NamedGem;
|
||||||
import org.mapstruct.ap.internal.prism.QualifierPrism;
|
import org.mapstruct.ap.internal.gem.QualifierGem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This selector selects a best match based on qualifier annotations.
|
* This selector selects a best match based on qualifier annotations.
|
||||||
@ -117,8 +116,8 @@ public class QualifierSelector implements MethodSelector {
|
|||||||
// Match! we have an annotation which has the @Qualifer marker ( could be @Named as well )
|
// Match! we have an annotation which has the @Qualifer marker ( could be @Named as well )
|
||||||
if ( typeUtils.isSameType( qualifierAnnotationType, namedAnnotationTypeMirror ) ) {
|
if ( typeUtils.isSameType( qualifierAnnotationType, namedAnnotationTypeMirror ) ) {
|
||||||
// Match! its an @Named, so do the additional check on name.
|
// Match! its an @Named, so do the additional check on name.
|
||||||
NamedPrism namedPrism = NamedPrism.getInstance( qualifierAnnotationMirror );
|
NamedGem named = NamedGem.instanceOn( qualifierAnnotationMirror );
|
||||||
if ( namedPrism.value() != null && qualfiedByNames.contains( namedPrism.value() ) ) {
|
if ( named.value().hasValue() && qualfiedByNames.contains( named.value().get() ) ) {
|
||||||
// Match! its an @Name and the value matches as well. Oh boy.
|
// Match! its an @Name and the value matches as well. Oh boy.
|
||||||
matchingQualifierCounter++;
|
matchingQualifierCounter++;
|
||||||
}
|
}
|
||||||
@ -168,7 +167,7 @@ public class QualifierSelector implements MethodSelector {
|
|||||||
|
|
||||||
private void addOnlyWhenQualifier( Set<AnnotationMirror> annotationSet, AnnotationMirror candidate ) {
|
private void addOnlyWhenQualifier( Set<AnnotationMirror> annotationSet, AnnotationMirror candidate ) {
|
||||||
// only add the candidate annotation when the candidate itself has the annotation 'Qualifier'
|
// only add the candidate annotation when the candidate itself has the annotation 'Qualifier'
|
||||||
if ( QualifierPrism.getInstanceOn( candidate.getAnnotationType().asElement() ) != null ) {
|
if ( QualifierGem.instanceOn( candidate.getAnnotationType().asElement() ) != null ) {
|
||||||
annotationSet.add( candidate );
|
annotationSet.add( candidate );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,18 +7,17 @@ package org.mapstruct.ap.internal.model.source.selector;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.lang.model.element.Element;
|
import javax.lang.model.element.Element;
|
||||||
import javax.lang.model.element.ElementKind;
|
import javax.lang.model.element.ElementKind;
|
||||||
import javax.lang.model.element.TypeElement;
|
import javax.lang.model.element.TypeElement;
|
||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
import javax.lang.model.util.Types;
|
import javax.lang.model.util.Types;
|
||||||
|
|
||||||
|
import org.mapstruct.ap.internal.gem.XmlElementRefGem;
|
||||||
import org.mapstruct.ap.internal.model.common.Type;
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
import org.mapstruct.ap.internal.model.source.Method;
|
import org.mapstruct.ap.internal.model.source.Method;
|
||||||
import org.mapstruct.ap.internal.model.source.SourceMethod;
|
import org.mapstruct.ap.internal.model.source.SourceMethod;
|
||||||
import org.mapstruct.ap.internal.prism.XmlElementDeclPrism;
|
import org.mapstruct.ap.internal.gem.XmlElementDeclGem;
|
||||||
import org.mapstruct.ap.internal.prism.XmlElementRefPrism;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the {@link javax.xml.bind.annotation.XmlElementRef} annotation on a field (of the mapping result type or its
|
* Finds the {@link javax.xml.bind.annotation.XmlElementRef} annotation on a field (of the mapping result type or its
|
||||||
@ -46,9 +45,9 @@ public class XmlElementDeclSelector implements MethodSelector {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends Method> List<SelectedMethod<T>> getMatchingMethods(Method mappingMethod,
|
public <T extends Method> List<SelectedMethod<T>> getMatchingMethods(Method mappingMethod,
|
||||||
List<SelectedMethod<T>> methods,
|
List<SelectedMethod<T>> methods,
|
||||||
List<Type> sourceTypes, Type targetType,
|
List<Type> sourceTypes, Type targetType,
|
||||||
SelectionCriteria criteria) {
|
SelectionCriteria criteria) {
|
||||||
|
|
||||||
List<SelectedMethod<T>> nameMatches = new ArrayList<>();
|
List<SelectedMethod<T>> nameMatches = new ArrayList<>();
|
||||||
List<SelectedMethod<T>> scopeMatches = new ArrayList<>();
|
List<SelectedMethod<T>> scopeMatches = new ArrayList<>();
|
||||||
@ -62,14 +61,15 @@ public class XmlElementDeclSelector implements MethodSelector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SourceMethod candidateMethod = (SourceMethod) candidate.getMethod();
|
SourceMethod candidateMethod = (SourceMethod) candidate.getMethod();
|
||||||
XmlElementDeclPrism xmlElementDecl = XmlElementDeclPrism.getInstanceOn( candidateMethod.getExecutable() );
|
XmlElementDeclGem xmlElementDecl =
|
||||||
|
XmlElementDeclGem.instanceOn( candidateMethod.getExecutable() );
|
||||||
|
|
||||||
if ( xmlElementDecl == null ) {
|
if ( xmlElementDecl == null ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = xmlElementDecl.name();
|
String name = xmlElementDecl.name().get();
|
||||||
TypeMirror scope = xmlElementDecl.scope();
|
TypeMirror scope = xmlElementDecl.scope().get();
|
||||||
|
|
||||||
boolean nameIsSetAndMatches = name != null && name.equals( xmlElementRefInfo.nameValue() );
|
boolean nameIsSetAndMatches = name != null && name.equals( xmlElementRefInfo.nameValue() );
|
||||||
boolean scopeIsSetAndMatches =
|
boolean scopeIsSetAndMatches =
|
||||||
@ -140,9 +140,9 @@ public class XmlElementDeclSelector implements MethodSelector {
|
|||||||
for ( Element enclosed : currentElement.getEnclosedElements() ) {
|
for ( Element enclosed : currentElement.getEnclosedElements() ) {
|
||||||
if ( enclosed.getKind().equals( ElementKind.FIELD )
|
if ( enclosed.getKind().equals( ElementKind.FIELD )
|
||||||
&& enclosed.getSimpleName().contentEquals( targetPropertyName ) ) {
|
&& enclosed.getSimpleName().contentEquals( targetPropertyName ) ) {
|
||||||
XmlElementRefPrism xmlElementRef = XmlElementRefPrism.getInstanceOn( enclosed );
|
XmlElementRefGem xmlElementRef = XmlElementRefGem.instanceOn( enclosed );
|
||||||
if ( xmlElementRef != null ) {
|
if ( xmlElementRef != null ) {
|
||||||
return new XmlElementRefInfo( xmlElementRef.name(), currentMirror );
|
return new XmlElementRefInfo( xmlElementRef.name().get(), currentMirror );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.internal.option;
|
package org.mapstruct.ap.internal.option;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.prism.ReportingPolicyPrism;
|
import org.mapstruct.ap.internal.gem.ReportingPolicyGem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The options passed to the code generator.
|
* The options passed to the code generator.
|
||||||
@ -16,14 +16,14 @@ import org.mapstruct.ap.internal.prism.ReportingPolicyPrism;
|
|||||||
public class Options {
|
public class Options {
|
||||||
private final boolean suppressGeneratorTimestamp;
|
private final boolean suppressGeneratorTimestamp;
|
||||||
private final boolean suppressGeneratorVersionComment;
|
private final boolean suppressGeneratorVersionComment;
|
||||||
private final ReportingPolicyPrism unmappedTargetPolicy;
|
private final ReportingPolicyGem unmappedTargetPolicy;
|
||||||
private final boolean alwaysGenerateSpi;
|
private final boolean alwaysGenerateSpi;
|
||||||
private final String defaultComponentModel;
|
private final String defaultComponentModel;
|
||||||
private final String defaultInjectionStrategy;
|
private final String defaultInjectionStrategy;
|
||||||
private final boolean verbose;
|
private final boolean verbose;
|
||||||
|
|
||||||
public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVersionComment,
|
public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVersionComment,
|
||||||
ReportingPolicyPrism unmappedTargetPolicy,
|
ReportingPolicyGem unmappedTargetPolicy,
|
||||||
String defaultComponentModel, String defaultInjectionStrategy,
|
String defaultComponentModel, String defaultInjectionStrategy,
|
||||||
boolean alwaysGenerateSpi, boolean verbose) {
|
boolean alwaysGenerateSpi, boolean verbose) {
|
||||||
this.suppressGeneratorTimestamp = suppressGeneratorTimestamp;
|
this.suppressGeneratorTimestamp = suppressGeneratorTimestamp;
|
||||||
@ -43,7 +43,7 @@ public class Options {
|
|||||||
return suppressGeneratorVersionComment;
|
return suppressGeneratorVersionComment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReportingPolicyPrism getUnmappedTargetPolicy() {
|
public ReportingPolicyGem getUnmappedTargetPolicy() {
|
||||||
return unmappedTargetPolicy;
|
return unmappedTargetPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright MapStruct Authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*/
|
|
||||||
package org.mapstruct.ap.internal.prism;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElementDecl;
|
|
||||||
import javax.xml.bind.annotation.XmlElementRef;
|
|
||||||
|
|
||||||
import org.mapstruct.AfterMapping;
|
|
||||||
import org.mapstruct.BeanMapping;
|
|
||||||
import org.mapstruct.BeforeMapping;
|
|
||||||
import org.mapstruct.Builder;
|
|
||||||
import org.mapstruct.Context;
|
|
||||||
import org.mapstruct.DecoratedWith;
|
|
||||||
import org.mapstruct.InheritConfiguration;
|
|
||||||
import org.mapstruct.InheritInverseConfiguration;
|
|
||||||
import org.mapstruct.IterableMapping;
|
|
||||||
import org.mapstruct.MapMapping;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.MapperConfig;
|
|
||||||
import org.mapstruct.Mapping;
|
|
||||||
import org.mapstruct.MappingTarget;
|
|
||||||
import org.mapstruct.Mappings;
|
|
||||||
import org.mapstruct.Named;
|
|
||||||
import org.mapstruct.ObjectFactory;
|
|
||||||
import org.mapstruct.Qualifier;
|
|
||||||
import org.mapstruct.TargetType;
|
|
||||||
import org.mapstruct.ValueMapping;
|
|
||||||
import org.mapstruct.ValueMappings;
|
|
||||||
|
|
||||||
import net.java.dev.hickory.prism.GeneratePrism;
|
|
||||||
import net.java.dev.hickory.prism.GeneratePrisms;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers the generation of prism types using <a href="https://java.net/projects/hickory">Hickory</a>.
|
|
||||||
*
|
|
||||||
* @author Gunnar Morling
|
|
||||||
*/
|
|
||||||
@GeneratePrisms({
|
|
||||||
@GeneratePrism(value = Mapper.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = Mapping.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = Mappings.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = IterableMapping.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = BeanMapping.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = MapMapping.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = TargetType.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = MappingTarget.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = DecoratedWith.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = MapperConfig.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = InheritConfiguration.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = InheritInverseConfiguration.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = Qualifier.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = Named.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = ObjectFactory.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = AfterMapping.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = BeforeMapping.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = ValueMapping.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = ValueMappings.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = Context.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = Builder.class, publicAccess = true),
|
|
||||||
|
|
||||||
// external types
|
|
||||||
@GeneratePrism(value = XmlElementDecl.class, publicAccess = true),
|
|
||||||
@GeneratePrism(value = XmlElementRef.class, publicAccess = true)
|
|
||||||
})
|
|
||||||
public class PrismGenerator {
|
|
||||||
|
|
||||||
}
|
|
@ -23,7 +23,7 @@ import org.mapstruct.ap.internal.model.Mapper;
|
|||||||
import org.mapstruct.ap.internal.model.MapperReference;
|
import org.mapstruct.ap.internal.model.MapperReference;
|
||||||
import org.mapstruct.ap.internal.model.common.Type;
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
import org.mapstruct.ap.internal.model.common.TypeFactory;
|
||||||
import org.mapstruct.ap.internal.prism.InjectionStrategyPrism;
|
import org.mapstruct.ap.internal.gem.InjectionStrategyGem;
|
||||||
import org.mapstruct.ap.internal.model.source.MapperOptions;
|
import org.mapstruct.ap.internal.model.source.MapperOptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +45,7 @@ public abstract class AnnotationBasedComponentModelProcessor implements ModelEle
|
|||||||
MapperOptions mapperAnnotation = MapperOptions.getInstanceOn( mapperTypeElement, context.getOptions() );
|
MapperOptions mapperAnnotation = MapperOptions.getInstanceOn( mapperTypeElement, context.getOptions() );
|
||||||
|
|
||||||
String componentModel = mapperAnnotation.componentModel();
|
String componentModel = mapperAnnotation.componentModel();
|
||||||
InjectionStrategyPrism injectionStrategy = mapperAnnotation.getInjectionStrategy();
|
InjectionStrategyGem injectionStrategy = mapperAnnotation.getInjectionStrategy();
|
||||||
|
|
||||||
if ( !getComponentModelIdentifier().equalsIgnoreCase( componentModel ) ) {
|
if ( !getComponentModelIdentifier().equalsIgnoreCase( componentModel ) ) {
|
||||||
return mapper;
|
return mapper;
|
||||||
@ -74,14 +74,14 @@ public abstract class AnnotationBasedComponentModelProcessor implements ModelEle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( injectionStrategy == InjectionStrategyPrism.CONSTRUCTOR ) {
|
if ( injectionStrategy == InjectionStrategyGem.CONSTRUCTOR ) {
|
||||||
buildConstructors( mapper );
|
buildConstructors( mapper );
|
||||||
}
|
}
|
||||||
|
|
||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void adjustDecorator(Mapper mapper, InjectionStrategyPrism injectionStrategy) {
|
protected void adjustDecorator(Mapper mapper, InjectionStrategyGem injectionStrategy) {
|
||||||
Decorator decorator = mapper.getDecorator();
|
Decorator decorator = mapper.getDecorator();
|
||||||
|
|
||||||
for ( Annotation typeAnnotation : getDecoratorAnnotations() ) {
|
for ( Annotation typeAnnotation : getDecoratorAnnotations() ) {
|
||||||
@ -220,15 +220,15 @@ public abstract class AnnotationBasedComponentModelProcessor implements ModelEle
|
|||||||
/**
|
/**
|
||||||
* @param originalReference the reference to be replaced
|
* @param originalReference the reference to be replaced
|
||||||
* @param annotations the list of annotations
|
* @param annotations the list of annotations
|
||||||
* @param injectionStrategyPrism strategy for injection
|
* @param injectionStrategy strategy for injection
|
||||||
* @return the mapper reference replacing the original one
|
* @return the mapper reference replacing the original one
|
||||||
*/
|
*/
|
||||||
protected Field replacementMapperReference(Field originalReference, List<Annotation> annotations,
|
protected Field replacementMapperReference(Field originalReference, List<Annotation> annotations,
|
||||||
InjectionStrategyPrism injectionStrategyPrism) {
|
InjectionStrategyGem injectionStrategy) {
|
||||||
boolean finalField =
|
boolean finalField =
|
||||||
injectionStrategyPrism == InjectionStrategyPrism.CONSTRUCTOR && !additionalPublicEmptyConstructor();
|
injectionStrategy == InjectionStrategyGem.CONSTRUCTOR && !additionalPublicEmptyConstructor();
|
||||||
|
|
||||||
boolean includeAnnotationsOnField = injectionStrategyPrism == InjectionStrategyPrism.FIELD;
|
boolean includeAnnotationsOnField = injectionStrategy == InjectionStrategyGem.FIELD;
|
||||||
|
|
||||||
return new AnnotationMapperReference(
|
return new AnnotationMapperReference(
|
||||||
originalReference.getType(),
|
originalReference.getType(),
|
||||||
|
@ -46,13 +46,13 @@ import org.mapstruct.ap.internal.model.source.Method;
|
|||||||
import org.mapstruct.ap.internal.model.source.SelectionParameters;
|
import org.mapstruct.ap.internal.model.source.SelectionParameters;
|
||||||
import org.mapstruct.ap.internal.model.source.SourceMethod;
|
import org.mapstruct.ap.internal.model.source.SourceMethod;
|
||||||
import org.mapstruct.ap.internal.option.Options;
|
import org.mapstruct.ap.internal.option.Options;
|
||||||
import org.mapstruct.ap.internal.prism.BuilderPrism;
|
import org.mapstruct.ap.internal.gem.BuilderGem;
|
||||||
import org.mapstruct.ap.internal.prism.DecoratedWithPrism;
|
import org.mapstruct.ap.internal.gem.DecoratedWithGem;
|
||||||
import org.mapstruct.ap.internal.prism.InheritConfigurationPrism;
|
import org.mapstruct.ap.internal.gem.InheritConfigurationGem;
|
||||||
import org.mapstruct.ap.internal.prism.InheritInverseConfigurationPrism;
|
import org.mapstruct.ap.internal.gem.InheritInverseConfigurationGem;
|
||||||
import org.mapstruct.ap.internal.prism.MapperPrism;
|
import org.mapstruct.ap.internal.gem.MapperGem;
|
||||||
import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism;
|
import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.processor.creation.MappingResolverImpl;
|
import org.mapstruct.ap.internal.processor.creation.MappingResolverImpl;
|
||||||
import org.mapstruct.ap.internal.util.AccessorNamingUtils;
|
import org.mapstruct.ap.internal.util.AccessorNamingUtils;
|
||||||
import org.mapstruct.ap.internal.util.FormattingMessager;
|
import org.mapstruct.ap.internal.util.FormattingMessager;
|
||||||
@ -132,7 +132,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
for ( TypeMirror usedMapper : mapperAnnotation.uses() ) {
|
for ( TypeMirror usedMapper : mapperAnnotation.uses() ) {
|
||||||
DefaultMapperReference mapperReference = DefaultMapperReference.getInstance(
|
DefaultMapperReference mapperReference = DefaultMapperReference.getInstance(
|
||||||
typeFactory.getType( usedMapper ),
|
typeFactory.getType( usedMapper ),
|
||||||
MapperPrism.getInstanceOn( typeUtils.asElement( usedMapper ) ) != null,
|
MapperGem.instanceOn( typeUtils.asElement( usedMapper ) ) != null,
|
||||||
typeFactory,
|
typeFactory,
|
||||||
variableNames
|
variableNames
|
||||||
);
|
);
|
||||||
@ -186,16 +186,16 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
|
|
||||||
private Decorator getDecorator(TypeElement element, List<SourceMethod> methods, String implName,
|
private Decorator getDecorator(TypeElement element, List<SourceMethod> methods, String implName,
|
||||||
String implPackage, SortedSet<Type> extraImports) {
|
String implPackage, SortedSet<Type> extraImports) {
|
||||||
DecoratedWithPrism decoratorPrism = DecoratedWithPrism.getInstanceOn( element );
|
DecoratedWithGem decoratedWith = DecoratedWithGem.instanceOn( element );
|
||||||
|
|
||||||
if ( decoratorPrism == null ) {
|
if ( decoratedWith == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeElement decoratorElement = (TypeElement) typeUtils.asElement( decoratorPrism.value() );
|
TypeElement decoratorElement = (TypeElement) typeUtils.asElement( decoratedWith.value().get() );
|
||||||
|
|
||||||
if ( !typeUtils.isAssignable( decoratorElement.asType(), element.asType() ) ) {
|
if ( !typeUtils.isAssignable( decoratorElement.asType(), element.asType() ) ) {
|
||||||
messager.printMessage( element, decoratorPrism.mirror, Message.DECORATOR_NO_SUBTYPE );
|
messager.printMessage( element, decoratedWith.mirror(), Message.DECORATOR_NO_SUBTYPE );
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MappingMethod> mappingMethods = new ArrayList<>( methods.size() );
|
List<MappingMethod> mappingMethods = new ArrayList<>( methods.size() );
|
||||||
@ -233,14 +233,14 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( !hasDelegateConstructor && !hasDefaultConstructor ) {
|
if ( !hasDelegateConstructor && !hasDefaultConstructor ) {
|
||||||
messager.printMessage( element, decoratorPrism.mirror, Message.DECORATOR_CONSTRUCTOR );
|
messager.printMessage( element, decoratedWith.mirror(), Message.DECORATOR_CONSTRUCTOR );
|
||||||
}
|
}
|
||||||
|
|
||||||
Decorator decorator = new Decorator.Builder()
|
Decorator decorator = new Decorator.Builder()
|
||||||
.elementUtils( elementUtils )
|
.elementUtils( elementUtils )
|
||||||
.typeFactory( typeFactory )
|
.typeFactory( typeFactory )
|
||||||
.mapperElement( element )
|
.mapperElement( element )
|
||||||
.decoratorPrism( decoratorPrism )
|
.decoratedWith( decoratedWith )
|
||||||
.methods( mappingMethods )
|
.methods( mappingMethods )
|
||||||
.hasDelegateConstructor( hasDelegateConstructor )
|
.hasDelegateConstructor( hasDelegateConstructor )
|
||||||
.options( options )
|
.options( options )
|
||||||
@ -305,7 +305,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
FormattingParameters keyFormattingParameters = null;
|
FormattingParameters keyFormattingParameters = null;
|
||||||
SelectionParameters valueSelectionParameters = null;
|
SelectionParameters valueSelectionParameters = null;
|
||||||
FormattingParameters valueFormattingParameters = null;
|
FormattingParameters valueFormattingParameters = null;
|
||||||
NullValueMappingStrategyPrism nullValueMappingStrategy = null;
|
NullValueMappingStrategyGem nullValueMappingStrategy = null;
|
||||||
|
|
||||||
if ( mappingOptions.getMapMapping() != null ) {
|
if ( mappingOptions.getMapMapping() != null ) {
|
||||||
keySelectionParameters = mappingOptions.getMapMapping().getKeySelectionParameters();
|
keySelectionParameters = mappingOptions.getMapMapping().getKeySelectionParameters();
|
||||||
@ -360,12 +360,12 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.messager.note( 1, Message.BEANMAPPING_CREATE_NOTE, method );
|
this.messager.note( 1, Message.BEANMAPPING_CREATE_NOTE, method );
|
||||||
BuilderPrism builderPrism = method.getOptions().getBeanMapping().getBuilderPrism();
|
BuilderGem builder = method.getOptions().getBeanMapping().getBuilder();
|
||||||
BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder();
|
BeanMappingMethod.Builder beanMappingBuilder = new BeanMappingMethod.Builder();
|
||||||
BeanMappingMethod beanMappingMethod = builder
|
BeanMappingMethod beanMappingMethod = beanMappingBuilder
|
||||||
.mappingContext( mappingContext )
|
.mappingContext( mappingContext )
|
||||||
.sourceMethod( method )
|
.sourceMethod( method )
|
||||||
.returnTypeBuilder( typeFactory.builderTypeFor( method.getReturnType(), builderPrism ) )
|
.returnTypeBuilder( typeFactory.builderTypeFor( method.getReturnType(), builder ) )
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if ( beanMappingMethod != null ) {
|
if ( beanMappingMethod != null ) {
|
||||||
@ -448,7 +448,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// apply auto inherited options
|
// apply auto inherited options
|
||||||
MappingInheritanceStrategyPrism inheritanceStrategy = mapperConfig.getMappingInheritanceStrategy();
|
MappingInheritanceStrategyGem inheritanceStrategy = mapperConfig.getMappingInheritanceStrategy();
|
||||||
if ( inheritanceStrategy.isAutoInherit() ) {
|
if ( inheritanceStrategy.isAutoInherit() ) {
|
||||||
|
|
||||||
// but.. there should not be an @InheritedConfiguration
|
// but.. there should not be an @InheritedConfiguration
|
||||||
@ -511,11 +511,10 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
List<SourceMethod> initializingMethods,
|
List<SourceMethod> initializingMethods,
|
||||||
MapperOptions mapperConfig) {
|
MapperOptions mapperConfig) {
|
||||||
SourceMethod resultMethod = null;
|
SourceMethod resultMethod = null;
|
||||||
InheritInverseConfigurationPrism inversePrism = InheritInverseConfigurationPrism.getInstanceOn(
|
InheritInverseConfigurationGem inverseConfiguration =
|
||||||
method.getExecutable()
|
InheritInverseConfigurationGem.instanceOn( method.getExecutable() );
|
||||||
);
|
|
||||||
|
|
||||||
if ( inversePrism != null ) {
|
if ( inverseConfiguration != null ) {
|
||||||
|
|
||||||
// method is configured as being inverse method, collect candidates
|
// method is configured as being inverse method, collect candidates
|
||||||
List<SourceMethod> candidates = new ArrayList<>();
|
List<SourceMethod> candidates = new ArrayList<>();
|
||||||
@ -525,7 +524,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = inversePrism.name();
|
String name = inverseConfiguration.name().get();
|
||||||
if ( candidates.size() == 1 ) {
|
if ( candidates.size() == 1 ) {
|
||||||
// no ambiguity: if no configuredBy is specified, or configuredBy specified and match
|
// no ambiguity: if no configuredBy is specified, or configuredBy specified and match
|
||||||
if ( name.isEmpty() ) {
|
if ( name.isEmpty() ) {
|
||||||
@ -535,7 +534,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
resultMethod = candidates.get( 0 );
|
resultMethod = candidates.get( 0 );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reportErrorWhenNonMatchingName( candidates.get( 0 ), method, inversePrism );
|
reportErrorWhenNonMatchingName( candidates.get( 0 ), method, inverseConfiguration );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( candidates.size() > 1 ) {
|
else if ( candidates.size() > 1 ) {
|
||||||
@ -552,10 +551,10 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
resultMethod = nameFilteredcandidates.get( 0 );
|
resultMethod = nameFilteredcandidates.get( 0 );
|
||||||
}
|
}
|
||||||
else if ( nameFilteredcandidates.size() > 1 ) {
|
else if ( nameFilteredcandidates.size() > 1 ) {
|
||||||
reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, inversePrism );
|
reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, inverseConfiguration );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reportErrorWhenAmbigousReverseMapping( candidates, method, inversePrism );
|
reportErrorWhenAmbigousReverseMapping( candidates, method, inverseConfiguration );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -588,11 +587,10 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
List<SourceMethod> initializingMethods,
|
List<SourceMethod> initializingMethods,
|
||||||
MapperOptions mapperConfig) {
|
MapperOptions mapperConfig) {
|
||||||
SourceMethod resultMethod = null;
|
SourceMethod resultMethod = null;
|
||||||
InheritConfigurationPrism forwardPrism = InheritConfigurationPrism.getInstanceOn(
|
InheritConfigurationGem inheritConfiguration =
|
||||||
method.getExecutable()
|
InheritConfigurationGem.instanceOn( method.getExecutable() );
|
||||||
);
|
|
||||||
|
|
||||||
if ( forwardPrism != null ) {
|
if ( inheritConfiguration != null ) {
|
||||||
|
|
||||||
List<SourceMethod> candidates = new ArrayList<>();
|
List<SourceMethod> candidates = new ArrayList<>();
|
||||||
for ( SourceMethod oneMethod : rawMethods ) {
|
for ( SourceMethod oneMethod : rawMethods ) {
|
||||||
@ -602,7 +600,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = forwardPrism.name();
|
String name = inheritConfiguration.name().get();
|
||||||
if ( candidates.size() == 1 ) {
|
if ( candidates.size() == 1 ) {
|
||||||
// no ambiguity: if no configuredBy is specified, or configuredBy specified and match
|
// no ambiguity: if no configuredBy is specified, or configuredBy specified and match
|
||||||
SourceMethod sourceMethod = first( candidates );
|
SourceMethod sourceMethod = first( candidates );
|
||||||
@ -613,7 +611,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
resultMethod = sourceMethod;
|
resultMethod = sourceMethod;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reportErrorWhenNonMatchingName( sourceMethod, method, forwardPrism );
|
reportErrorWhenNonMatchingName( sourceMethod, method, inheritConfiguration );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( candidates.size() > 1 ) {
|
else if ( candidates.size() > 1 ) {
|
||||||
@ -630,10 +628,10 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
resultMethod = first( nameFilteredcandidates );
|
resultMethod = first( nameFilteredcandidates );
|
||||||
}
|
}
|
||||||
else if ( nameFilteredcandidates.size() > 1 ) {
|
else if ( nameFilteredcandidates.size() > 1 ) {
|
||||||
reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, forwardPrism );
|
reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, inheritConfiguration );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reportErrorWhenAmbigousMapping( candidates, method, forwardPrism );
|
reportErrorWhenAmbigousMapping( candidates, method, inheritConfiguration );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -642,17 +640,17 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reportErrorWhenAmbigousReverseMapping(List<SourceMethod> candidates, SourceMethod method,
|
private void reportErrorWhenAmbigousReverseMapping(List<SourceMethod> candidates, SourceMethod method,
|
||||||
InheritInverseConfigurationPrism inversePrism) {
|
InheritInverseConfigurationGem inverseGem) {
|
||||||
|
|
||||||
List<String> candidateNames = new ArrayList<>();
|
List<String> candidateNames = new ArrayList<>();
|
||||||
for ( SourceMethod candidate : candidates ) {
|
for ( SourceMethod candidate : candidates ) {
|
||||||
candidateNames.add( candidate.getName() );
|
candidateNames.add( candidate.getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = inversePrism.name();
|
String name = inverseGem.name().get();
|
||||||
if ( name.isEmpty() ) {
|
if ( name.isEmpty() ) {
|
||||||
messager.printMessage( method.getExecutable(),
|
messager.printMessage( method.getExecutable(),
|
||||||
inversePrism.mirror,
|
inverseGem.mirror(),
|
||||||
Message.INHERITINVERSECONFIGURATION_DUPLICATES,
|
Message.INHERITINVERSECONFIGURATION_DUPLICATES,
|
||||||
Strings.join( candidateNames, "(), " )
|
Strings.join( candidateNames, "(), " )
|
||||||
|
|
||||||
@ -660,7 +658,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
messager.printMessage( method.getExecutable(),
|
messager.printMessage( method.getExecutable(),
|
||||||
inversePrism.mirror,
|
inverseGem.mirror(),
|
||||||
Message.INHERITINVERSECONFIGURATION_INVALID_NAME,
|
Message.INHERITINVERSECONFIGURATION_INVALID_NAME,
|
||||||
Strings.join( candidateNames, "(), " ),
|
Strings.join( candidateNames, "(), " ),
|
||||||
name
|
name
|
||||||
@ -670,40 +668,40 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reportErrorWhenSeveralNamesMatch(List<SourceMethod> candidates, SourceMethod method,
|
private void reportErrorWhenSeveralNamesMatch(List<SourceMethod> candidates, SourceMethod method,
|
||||||
InheritInverseConfigurationPrism inversePrism) {
|
InheritInverseConfigurationGem inverseGem) {
|
||||||
|
|
||||||
messager.printMessage( method.getExecutable(),
|
messager.printMessage( method.getExecutable(),
|
||||||
inversePrism.mirror,
|
inverseGem.mirror(),
|
||||||
Message.INHERITINVERSECONFIGURATION_DUPLICATE_MATCHES,
|
Message.INHERITINVERSECONFIGURATION_DUPLICATE_MATCHES,
|
||||||
inversePrism.name(),
|
inverseGem.name().get(),
|
||||||
Strings.join( candidates, ", " )
|
Strings.join( candidates, ", " )
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method,
|
private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method,
|
||||||
InheritInverseConfigurationPrism inversePrism) {
|
InheritInverseConfigurationGem inverseGem) {
|
||||||
|
|
||||||
messager.printMessage( method.getExecutable(),
|
messager.printMessage( method.getExecutable(),
|
||||||
inversePrism.mirror,
|
inverseGem.mirror(),
|
||||||
Message.INHERITINVERSECONFIGURATION_NO_NAME_MATCH,
|
Message.INHERITINVERSECONFIGURATION_NO_NAME_MATCH,
|
||||||
inversePrism.name(),
|
inverseGem.name().get(),
|
||||||
onlyCandidate.getName()
|
onlyCandidate.getName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reportErrorWhenAmbigousMapping(List<SourceMethod> candidates, SourceMethod method,
|
private void reportErrorWhenAmbigousMapping(List<SourceMethod> candidates, SourceMethod method,
|
||||||
InheritConfigurationPrism prism) {
|
InheritConfigurationGem gem) {
|
||||||
|
|
||||||
List<String> candidateNames = new ArrayList<>();
|
List<String> candidateNames = new ArrayList<>();
|
||||||
for ( SourceMethod candidate : candidates ) {
|
for ( SourceMethod candidate : candidates ) {
|
||||||
candidateNames.add( candidate.getName() );
|
candidateNames.add( candidate.getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = prism.name();
|
String name = gem.name().get();
|
||||||
if ( name.isEmpty() ) {
|
if ( name.isEmpty() ) {
|
||||||
messager.printMessage( method.getExecutable(),
|
messager.printMessage( method.getExecutable(),
|
||||||
prism.mirror,
|
gem.mirror(),
|
||||||
Message.INHERITCONFIGURATION_DUPLICATES,
|
Message.INHERITCONFIGURATION_DUPLICATES,
|
||||||
Strings.join( candidateNames, "(), " )
|
Strings.join( candidateNames, "(), " )
|
||||||
);
|
);
|
||||||
@ -711,7 +709,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
else {
|
else {
|
||||||
messager.printMessage(
|
messager.printMessage(
|
||||||
method.getExecutable(),
|
method.getExecutable(),
|
||||||
prism.mirror,
|
gem.mirror(),
|
||||||
Message.INHERITCONFIGURATION_INVALIDNAME,
|
Message.INHERITCONFIGURATION_INVALIDNAME,
|
||||||
Strings.join( candidateNames, "(), " ),
|
Strings.join( candidateNames, "(), " ),
|
||||||
name
|
name
|
||||||
@ -720,25 +718,25 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reportErrorWhenSeveralNamesMatch(List<SourceMethod> candidates, SourceMethod method,
|
private void reportErrorWhenSeveralNamesMatch(List<SourceMethod> candidates, SourceMethod method,
|
||||||
InheritConfigurationPrism prism) {
|
InheritConfigurationGem gem) {
|
||||||
|
|
||||||
messager.printMessage(
|
messager.printMessage(
|
||||||
method.getExecutable(),
|
method.getExecutable(),
|
||||||
prism.mirror,
|
gem.mirror(),
|
||||||
Message.INHERITCONFIGURATION_DUPLICATE_MATCHES,
|
Message.INHERITCONFIGURATION_DUPLICATE_MATCHES,
|
||||||
prism.name(),
|
gem.name().get(),
|
||||||
Strings.join( candidates, ", " )
|
Strings.join( candidates, ", " )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method,
|
private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method,
|
||||||
InheritConfigurationPrism prims) {
|
InheritConfigurationGem gem) {
|
||||||
|
|
||||||
messager.printMessage(
|
messager.printMessage(
|
||||||
method.getExecutable(),
|
method.getExecutable(),
|
||||||
prims.mirror,
|
gem.mirror(),
|
||||||
Message.INHERITCONFIGURATION_NO_NAME_MATCH,
|
Message.INHERITCONFIGURATION_NO_NAME_MATCH,
|
||||||
prims.name(),
|
gem.name().get(),
|
||||||
onlyCandidate.getName()
|
onlyCandidate.getName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -34,14 +34,14 @@ import org.mapstruct.ap.internal.model.source.MappingOptions;
|
|||||||
import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods;
|
import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods;
|
||||||
import org.mapstruct.ap.internal.model.source.SourceMethod;
|
import org.mapstruct.ap.internal.model.source.SourceMethod;
|
||||||
import org.mapstruct.ap.internal.model.source.ValueMappingOptions;
|
import org.mapstruct.ap.internal.model.source.ValueMappingOptions;
|
||||||
import org.mapstruct.ap.internal.prism.BeanMappingPrism;
|
import org.mapstruct.ap.internal.gem.BeanMappingGem;
|
||||||
import org.mapstruct.ap.internal.prism.IterableMappingPrism;
|
import org.mapstruct.ap.internal.gem.IterableMappingGem;
|
||||||
import org.mapstruct.ap.internal.prism.MapMappingPrism;
|
import org.mapstruct.ap.internal.gem.MapMappingGem;
|
||||||
import org.mapstruct.ap.internal.prism.MappingPrism;
|
import org.mapstruct.ap.internal.gem.MappingGem;
|
||||||
import org.mapstruct.ap.internal.prism.MappingsPrism;
|
import org.mapstruct.ap.internal.gem.MappingsGem;
|
||||||
import org.mapstruct.ap.internal.prism.ObjectFactoryPrism;
|
import org.mapstruct.ap.internal.gem.ObjectFactoryGem;
|
||||||
import org.mapstruct.ap.internal.prism.ValueMappingPrism;
|
import org.mapstruct.ap.internal.gem.ValueMappingGem;
|
||||||
import org.mapstruct.ap.internal.prism.ValueMappingsPrism;
|
import org.mapstruct.ap.internal.gem.ValueMappingsGem;
|
||||||
import org.mapstruct.ap.internal.util.AccessorNamingUtils;
|
import org.mapstruct.ap.internal.util.AccessorNamingUtils;
|
||||||
import org.mapstruct.ap.internal.util.AnnotationProcessingException;
|
import org.mapstruct.ap.internal.util.AnnotationProcessingException;
|
||||||
import org.mapstruct.ap.internal.util.Executables;
|
import org.mapstruct.ap.internal.util.Executables;
|
||||||
@ -247,7 +247,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
|||||||
retrieveContextProvidedMethods( contextParameters, mapperToImplement, mapperOptions );
|
retrieveContextProvidedMethods( contextParameters, mapperToImplement, mapperOptions );
|
||||||
|
|
||||||
BeanMappingOptions beanMappingOptions = BeanMappingOptions.getInstanceOn(
|
BeanMappingOptions beanMappingOptions = BeanMappingOptions.getInstanceOn(
|
||||||
BeanMappingPrism.getInstanceOn( method ),
|
BeanMappingGem.instanceOn( method ),
|
||||||
mapperOptions,
|
mapperOptions,
|
||||||
method,
|
method,
|
||||||
messager,
|
messager,
|
||||||
@ -257,16 +257,16 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
|||||||
Set<MappingOptions> mappingOptions =
|
Set<MappingOptions> mappingOptions =
|
||||||
getMappings( method, method, beanMappingOptions, new LinkedHashSet<>(), new HashSet<>() );
|
getMappings( method, method, beanMappingOptions, new LinkedHashSet<>(), new HashSet<>() );
|
||||||
|
|
||||||
IterableMappingOptions iterableMappingOptions = IterableMappingOptions.fromPrism(
|
IterableMappingOptions iterableMappingOptions = IterableMappingOptions.fromGem(
|
||||||
IterableMappingPrism.getInstanceOn( method ),
|
IterableMappingGem.instanceOn( method ),
|
||||||
mapperOptions,
|
mapperOptions,
|
||||||
method,
|
method,
|
||||||
messager,
|
messager,
|
||||||
typeUtils
|
typeUtils
|
||||||
);
|
);
|
||||||
|
|
||||||
MapMappingOptions mapMappingOptions = MapMappingOptions.fromPrism(
|
MapMappingOptions mapMappingOptions = MapMappingOptions.fromGem(
|
||||||
MapMappingPrism.getInstanceOn( method ),
|
MapMappingGem.instanceOn( method ),
|
||||||
mapperOptions,
|
mapperOptions,
|
||||||
method,
|
method,
|
||||||
messager,
|
messager,
|
||||||
@ -359,7 +359,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasFactoryAnnotation(ExecutableElement method) {
|
private boolean hasFactoryAnnotation(ExecutableElement method) {
|
||||||
return ObjectFactoryPrism.getInstanceOn( method ) != null;
|
return ObjectFactoryGem.instanceOn( method ) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isVoid(Type returnType) {
|
private boolean isVoid(Type returnType) {
|
||||||
@ -514,25 +514,25 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
|||||||
* @param method The method of interest
|
* @param method The method of interest
|
||||||
* @param element Element of interest: method, or (meta) annotation
|
* @param element Element of interest: method, or (meta) annotation
|
||||||
* @param beanMapping options coming from bean mapping method
|
* @param beanMapping options coming from bean mapping method
|
||||||
* @param mappings LinkedSet of mappings found so far
|
* @param mappingOptions LinkedSet of mappings found so far
|
||||||
*
|
*
|
||||||
* @return The mappings for the given method, keyed by target property name
|
* @return The mappings for the given method, keyed by target property name
|
||||||
*/
|
*/
|
||||||
private Set<MappingOptions> getMappings(ExecutableElement method, Element element,
|
private Set<MappingOptions> getMappings(ExecutableElement method, Element element,
|
||||||
BeanMappingOptions beanMapping, Set<MappingOptions> mappings,
|
BeanMappingOptions beanMapping, Set<MappingOptions> mappingOptions,
|
||||||
Set<Element> handledElements) {
|
Set<Element> handledElements) {
|
||||||
|
|
||||||
for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) {
|
for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) {
|
||||||
Element lElement = annotationMirror.getAnnotationType().asElement();
|
Element lElement = annotationMirror.getAnnotationType().asElement();
|
||||||
if ( isAnnotation( lElement, MAPPING_FQN ) ) {
|
if ( isAnnotation( lElement, MAPPING_FQN ) ) {
|
||||||
// although getInstanceOn does a search on annotation mirrors, the order is preserved
|
// although getInstanceOn does a search on annotation mirrors, the order is preserved
|
||||||
MappingPrism mappingPrism = MappingPrism.getInstanceOn( element );
|
MappingGem mapping = MappingGem.instanceOn( element );
|
||||||
MappingOptions.addInstance( mappingPrism, method, beanMapping, messager, typeUtils, mappings );
|
MappingOptions.addInstance( mapping, method, beanMapping, messager, typeUtils, mappingOptions );
|
||||||
}
|
}
|
||||||
else if ( isAnnotation( lElement, MAPPINGS_FQN ) ) {
|
else if ( isAnnotation( lElement, MAPPINGS_FQN ) ) {
|
||||||
// although getInstanceOn does a search on annotation mirrors, the order is preserved
|
// although getInstanceOn does a search on annotation mirrors, the order is preserved
|
||||||
MappingsPrism mappingsPrism = MappingsPrism.getInstanceOn( element );
|
MappingsGem mappings = MappingsGem.instanceOn( element );
|
||||||
MappingOptions.addInstances( mappingsPrism, method, beanMapping, messager, typeUtils, mappings );
|
MappingOptions.addInstances( mappings, method, beanMapping, messager, typeUtils, mappingOptions );
|
||||||
}
|
}
|
||||||
else if ( !isAnnotationInPackage( lElement, JAVA_LANG_ANNOTATION_PGK )
|
else if ( !isAnnotationInPackage( lElement, JAVA_LANG_ANNOTATION_PGK )
|
||||||
&& !isAnnotationInPackage( lElement, ORG_MAPSTRUCT_PKG )
|
&& !isAnnotationInPackage( lElement, ORG_MAPSTRUCT_PKG )
|
||||||
@ -540,10 +540,10 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
|||||||
) {
|
) {
|
||||||
// recur over annotation mirrors
|
// recur over annotation mirrors
|
||||||
handledElements.add( lElement );
|
handledElements.add( lElement );
|
||||||
getMappings( method, lElement, beanMapping, mappings, handledElements );
|
getMappings( method, lElement, beanMapping, mappingOptions, handledElements );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mappings;
|
return mappingOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAnnotationInPackage(Element element, String packageFQN ) {
|
private boolean isAnnotationInPackage(Element element, String packageFQN ) {
|
||||||
@ -571,18 +571,18 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
|||||||
private List<ValueMappingOptions> getValueMappings(ExecutableElement method) {
|
private List<ValueMappingOptions> getValueMappings(ExecutableElement method) {
|
||||||
List<ValueMappingOptions> valueMappings = new ArrayList<>();
|
List<ValueMappingOptions> valueMappings = new ArrayList<>();
|
||||||
|
|
||||||
ValueMappingPrism mappingAnnotation = ValueMappingPrism.getInstanceOn( method );
|
ValueMappingGem mappingAnnotation = ValueMappingGem.instanceOn( method );
|
||||||
ValueMappingsPrism mappingsAnnotation = ValueMappingsPrism.getInstanceOn( method );
|
ValueMappingsGem mappingsAnnotation = ValueMappingsGem.instanceOn( method );
|
||||||
|
|
||||||
if ( mappingAnnotation != null ) {
|
if ( mappingAnnotation != null ) {
|
||||||
ValueMappingOptions valueMapping = ValueMappingOptions.fromMappingPrism( mappingAnnotation );
|
ValueMappingOptions valueMapping = ValueMappingOptions.fromMappingGem( mappingAnnotation );
|
||||||
if ( valueMapping != null ) {
|
if ( valueMapping != null ) {
|
||||||
valueMappings.add( valueMapping );
|
valueMappings.add( valueMapping );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mappingsAnnotation != null ) {
|
if ( mappingsAnnotation != null ) {
|
||||||
ValueMappingOptions.fromMappingsPrism( mappingsAnnotation, method, messager, valueMappings );
|
ValueMappingOptions.fromMappingsGem( mappingsAnnotation, method, messager, valueMappings );
|
||||||
}
|
}
|
||||||
|
|
||||||
return valueMappings;
|
return valueMappings;
|
||||||
|
@ -43,7 +43,7 @@ import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod;
|
|||||||
import org.mapstruct.ap.internal.model.source.selector.MethodSelectors;
|
import org.mapstruct.ap.internal.model.source.selector.MethodSelectors;
|
||||||
import org.mapstruct.ap.internal.model.source.selector.SelectedMethod;
|
import org.mapstruct.ap.internal.model.source.selector.SelectedMethod;
|
||||||
import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria;
|
import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria;
|
||||||
import org.mapstruct.ap.internal.prism.ReportingPolicyPrism;
|
import org.mapstruct.ap.internal.gem.ReportingPolicyGem;
|
||||||
import org.mapstruct.ap.internal.util.Collections;
|
import org.mapstruct.ap.internal.util.Collections;
|
||||||
import org.mapstruct.ap.internal.util.FormattingMessager;
|
import org.mapstruct.ap.internal.util.FormattingMessager;
|
||||||
import org.mapstruct.ap.internal.util.Message;
|
import org.mapstruct.ap.internal.util.Message;
|
||||||
@ -664,11 +664,11 @@ public class MappingResolverImpl implements MappingResolver {
|
|||||||
void reportMessageWhenNarrowing(FormattingMessager messager, ResolvingAttempt attempt) {
|
void reportMessageWhenNarrowing(FormattingMessager messager, ResolvingAttempt attempt) {
|
||||||
|
|
||||||
if ( NativeTypes.isNarrowing( sourceType.getFullyQualifiedName(), targetType.getFullyQualifiedName() ) ) {
|
if ( NativeTypes.isNarrowing( sourceType.getFullyQualifiedName(), targetType.getFullyQualifiedName() ) ) {
|
||||||
ReportingPolicyPrism policy = attempt.mappingMethod.getOptions().getMapper().typeConversionPolicy();
|
ReportingPolicyGem policy = attempt.mappingMethod.getOptions().getMapper().typeConversionPolicy();
|
||||||
if ( policy == ReportingPolicyPrism.WARN ) {
|
if ( policy == ReportingPolicyGem.WARN ) {
|
||||||
report( messager, attempt, Message.CONVERSION_LOSSY_WARNING );
|
report( messager, attempt, Message.CONVERSION_LOSSY_WARNING );
|
||||||
}
|
}
|
||||||
else if ( policy == ReportingPolicyPrism.ERROR ) {
|
else if ( policy == ReportingPolicyGem.ERROR ) {
|
||||||
report( messager, attempt, Message.CONVERSION_LOSSY_ERROR );
|
report( messager, attempt, Message.CONVERSION_LOSSY_ERROR );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@ import javax.lang.model.type.TypeKind;
|
|||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
import javax.lang.model.util.Elements;
|
import javax.lang.model.util.Elements;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.prism.AfterMappingPrism;
|
import org.mapstruct.ap.internal.gem.AfterMappingGem;
|
||||||
import org.mapstruct.ap.internal.prism.BeforeMappingPrism;
|
import org.mapstruct.ap.internal.gem.BeforeMappingGem;
|
||||||
import org.mapstruct.ap.internal.util.accessor.Accessor;
|
import org.mapstruct.ap.internal.util.accessor.Accessor;
|
||||||
import org.mapstruct.ap.spi.TypeHierarchyErroneousException;
|
import org.mapstruct.ap.spi.TypeHierarchyErroneousException;
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ public class Executables {
|
|||||||
* @return {@code true}, if the executable element is a method annotated with {@code @AfterMapping}
|
* @return {@code true}, if the executable element is a method annotated with {@code @AfterMapping}
|
||||||
*/
|
*/
|
||||||
public static boolean isAfterMappingMethod(ExecutableElement executableElement) {
|
public static boolean isAfterMappingMethod(ExecutableElement executableElement) {
|
||||||
return AfterMappingPrism.getInstanceOn( executableElement ) != null;
|
return AfterMappingGem.instanceOn( executableElement ) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -241,6 +241,6 @@ public class Executables {
|
|||||||
* @return {@code true}, if the executable element is a method annotated with {@code @BeforeMapping}
|
* @return {@code true}, if the executable element is a method annotated with {@code @BeforeMapping}
|
||||||
*/
|
*/
|
||||||
public static boolean isBeforeMappingMethod(ExecutableElement executableElement) {
|
public static boolean isBeforeMappingMethod(ExecutableElement executableElement) {
|
||||||
return BeforeMappingPrism.getInstanceOn( executableElement ) != null;
|
return BeforeMappingGem.instanceOn( executableElement ) != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,13 @@
|
|||||||
*
|
*
|
||||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.test.prism;
|
package org.mapstruct.ap.test.gem;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mapstruct.MappingConstants;
|
import org.mapstruct.MappingConstants;
|
||||||
import org.mapstruct.ap.internal.prism.MappingConstantsPrism;
|
import org.mapstruct.ap.internal.gem.MappingConstantsGem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test constants values
|
* Test constants values
|
||||||
@ -20,8 +20,8 @@ public class ConstantTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constantsShouldBeEqual() {
|
public void constantsShouldBeEqual() {
|
||||||
assertThat( MappingConstants.ANY_REMAINING ).isEqualTo( MappingConstantsPrism.ANY_REMAINING );
|
assertThat( MappingConstants.ANY_REMAINING ).isEqualTo( MappingConstantsGem.ANY_REMAINING );
|
||||||
assertThat( MappingConstants.ANY_UNMAPPED ).isEqualTo( MappingConstantsPrism.ANY_UNMAPPED );
|
assertThat( MappingConstants.ANY_UNMAPPED ).isEqualTo( MappingConstantsGem.ANY_UNMAPPED );
|
||||||
assertThat( MappingConstants.NULL ).isEqualTo( MappingConstantsPrism.NULL );
|
assertThat( MappingConstants.NULL ).isEqualTo( MappingConstantsGem.NULL );
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.test.prism;
|
package org.mapstruct.ap.test.gem;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@ -18,53 +18,53 @@ import org.mapstruct.MappingInheritanceStrategy;
|
|||||||
import org.mapstruct.NullValueCheckStrategy;
|
import org.mapstruct.NullValueCheckStrategy;
|
||||||
import org.mapstruct.NullValueMappingStrategy;
|
import org.mapstruct.NullValueMappingStrategy;
|
||||||
import org.mapstruct.ReportingPolicy;
|
import org.mapstruct.ReportingPolicy;
|
||||||
import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.InjectionStrategyPrism;
|
import org.mapstruct.ap.internal.gem.InjectionStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism;
|
import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism;
|
import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem;
|
||||||
import org.mapstruct.ap.internal.prism.ReportingPolicyPrism;
|
import org.mapstruct.ap.internal.gem.ReportingPolicyGem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for manually created prisms on enumeration types
|
* Test for manually created gems on enumeration types
|
||||||
*
|
*
|
||||||
* @author Andreas Gudian
|
* @author Andreas Gudian
|
||||||
*/
|
*/
|
||||||
public class EnumPrismsTest {
|
public class EnumGemsTest {
|
||||||
@Test
|
@Test
|
||||||
public void collectionMappingStrategyPrismIsCorrect() {
|
public void collectionMappingStrategyGemIsCorrect() {
|
||||||
assertThat( namesOf( CollectionMappingStrategy.values() ) ).isEqualTo(
|
assertThat( namesOf( CollectionMappingStrategy.values() ) ).isEqualTo(
|
||||||
namesOf( CollectionMappingStrategyPrism.values() ) );
|
namesOf( CollectionMappingStrategyGem.values() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mappingInheritanceStrategyPrismIsCorrect() {
|
public void mappingInheritanceStrategyGemIsCorrect() {
|
||||||
assertThat( namesOf( MappingInheritanceStrategy.values() ) ).isEqualTo(
|
assertThat( namesOf( MappingInheritanceStrategy.values() ) ).isEqualTo(
|
||||||
namesOf( MappingInheritanceStrategyPrism.values() ) );
|
namesOf( MappingInheritanceStrategyGem.values() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nullValueCheckStrategyPrismIsCorrect() {
|
public void nullValueCheckStrategyGemIsCorrect() {
|
||||||
assertThat( namesOf( NullValueCheckStrategy.values() ) ).isEqualTo(
|
assertThat( namesOf( NullValueCheckStrategy.values() ) ).isEqualTo(
|
||||||
namesOf( NullValueCheckStrategyPrism.values() ) );
|
namesOf( NullValueCheckStrategyGem.values() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nullValueMappingStrategyPrismIsCorrect() {
|
public void nullValueMappingStrategyGemIsCorrect() {
|
||||||
assertThat( namesOf( NullValueMappingStrategy.values() ) ).isEqualTo(
|
assertThat( namesOf( NullValueMappingStrategy.values() ) ).isEqualTo(
|
||||||
namesOf( NullValueMappingStrategyPrism.values() ) );
|
namesOf( NullValueMappingStrategyGem.values() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void reportingPolicyPrismIsCorrect() {
|
public void reportingPolicyGemIsCorrect() {
|
||||||
assertThat( namesOf( ReportingPolicy.values() ) ).isEqualTo(
|
assertThat( namesOf( ReportingPolicy.values() ) ).isEqualTo(
|
||||||
namesOf( ReportingPolicyPrism.values() ) );
|
namesOf( ReportingPolicyGem.values() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void injectionStrategyPrismIsCorrect() {
|
public void injectionStrategyGemIsCorrect() {
|
||||||
assertThat( namesOf( InjectionStrategy.values() ) ).isEqualTo(
|
assertThat( namesOf( InjectionStrategy.values() ) ).isEqualTo(
|
||||||
namesOf( InjectionStrategyPrism.values() ) );
|
namesOf( InjectionStrategyGem.values() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> namesOf(Enum<?>[] values) {
|
private static List<String> namesOf(Enum<?>[] values) {
|
@ -144,6 +144,7 @@ abstract class CompilingStatement extends Statement {
|
|||||||
"freemarker",
|
"freemarker",
|
||||||
"javax.inject",
|
"javax.inject",
|
||||||
"spring-context",
|
"spring-context",
|
||||||
|
"gem-api",
|
||||||
"joda-time" };
|
"joda-time" };
|
||||||
|
|
||||||
return filterBootClassPath( whitelist );
|
return filterBootClassPath( whitelist );
|
||||||
|
@ -145,7 +145,7 @@ from the root of the project directory. To skip the distribution module, run
|
|||||||
|
|
||||||
## Importing into IDE
|
## Importing into IDE
|
||||||
|
|
||||||
MapStruct uses the hickory annotation processor to generate mapping prisms for it's own annotations.
|
MapStruct uses the gem annotation processor to generate mapping gems for it's own annotations.
|
||||||
Therefore for seamless integration within an IDE annotation processing needs to be enabled.
|
Therefore for seamless integration within an IDE annotation processing needs to be enabled.
|
||||||
|
|
||||||
### IntelliJ
|
### IntelliJ
|
||||||
|
Loading…
x
Reference in New Issue
Block a user