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