#2255 Add constants for componentModel

This commit is contained in:
Tomas Poledny 2020-11-05 14:09:30 +01:00 committed by Filip Hrisafov
parent 700293f089
commit 4223e3ab81
46 changed files with 166 additions and 48 deletions

View File

@ -35,7 +35,7 @@ import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION;
* </p> * </p>
* <pre><code class='java'> * <pre><code class='java'>
* // we have MarkMapper (map field "mark" to field "name" to upper case) * // we have MarkMapper (map field "mark" to field "name" to upper case)
* &#64;Mapper(componentModel = "spring") * &#64;Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
* public class MarkMapper { * public class MarkMapper {
* public String mapMark(String mark) { * public String mapMark(String mark) {
* return mark.toUpperCase(); * return mark.toUpperCase();
@ -43,7 +43,7 @@ import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION;
* } * }
* // we have CarMapper * // we have CarMapper
* &#64;Mapper( * &#64;Mapper(
* componentModel = "spring", * componentModel = MappingConstants.ComponentModel.SPRING,
* uses = MarkMapper.class, * uses = MarkMapper.class,
* injectionStrategy = InjectionStrategy.CONSTRUCTOR) * injectionStrategy = InjectionStrategy.CONSTRUCTOR)
* public interface CarMapper { * public interface CarMapper {
@ -148,7 +148,7 @@ public @interface Mapper {
* *
* @return The component model for the generated mapper. * @return The component model for the generated mapper.
*/ */
String componentModel() default "default"; String componentModel() default MappingConstants.ComponentModel.DEFAULT;
/** /**
* Specifies the name of the implementation class. The {@code <CLASS_NAME>} will be replaced by the * Specifies the name of the implementation class. The {@code <CLASS_NAME>} will be replaced by the

View File

@ -135,7 +135,7 @@ public @interface MapperConfig {
* *
* @return The component model for the generated mapper. * @return The component model for the generated mapper.
*/ */
String componentModel() default "default"; String componentModel() default MappingConstants.ComponentModel.DEFAULT;
/** /**
* Specifies the name of the implementation class. The {@code <CLASS_NAME>} will be replaced by the * Specifies the name of the implementation class. The {@code <CLASS_NAME>} will be replaced by the

View File

@ -66,4 +66,49 @@ public final class MappingConstants {
*/ */
public static final String STRIP_PREFIX_TRANSFORMATION = "stripPrefix"; public static final String STRIP_PREFIX_TRANSFORMATION = "stripPrefix";
/**
* Specifies the component model constants to which the generated mapper should adhere.
* It can be used with the annotation {@link Mapper#componentModel()} or {@link MapperConfig#componentModel()}
*
* <p>
* <strong>Example:</strong>
* </p>
* <pre><code class='java'>
* // Spring component model
* &#64;Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
* </code></pre>
*
* @since 1.5.0
*/
public static final class ComponentModel {
private ComponentModel() {
}
/**
* The mapper uses no component model, instances are typically retrieved
* via {@link org.mapstruct.factory.Mappers#getMapper(java.lang.Class)}
*
*/
public static final String DEFAULT = "default";
/**
* The generated mapper is an application-scoped CDI bean and can be retrieved via @Inject
*/
public static final String CDI = "cdi";
/**
* The generated mapper is a Spring bean and can be retrieved via @Autowired
*
*/
public static final String SPRING = "spring";
/**
* The generated mapper is annotated with @javax.inject.Named and @Singleton, and can be retrieved via @Inject
*
*/
public static final String JSR330 = "jsr330";
}
} }

View File

@ -69,14 +69,14 @@ Note that mappers generated by MapStruct are stateless and thread-safe and thus
If you're working with a dependency injection framework such as http://jcp.org/en/jsr/detail?id=346[CDI] (Contexts and Dependency Injection for Java^TM^ EE) or the http://www.springsource.org/spring-framework[Spring Framework], it is recommended to obtain mapper objects via dependency injection and *not* via the `Mappers` class as described above. For that purpose you can specify the component model which generated mapper classes should be based on either via `@Mapper#componentModel` or using a processor option as described in <<configuration-options>>. If you're working with a dependency injection framework such as http://jcp.org/en/jsr/detail?id=346[CDI] (Contexts and Dependency Injection for Java^TM^ EE) or the http://www.springsource.org/spring-framework[Spring Framework], it is recommended to obtain mapper objects via dependency injection and *not* via the `Mappers` class as described above. For that purpose you can specify the component model which generated mapper classes should be based on either via `@Mapper#componentModel` or using a processor option as described in <<configuration-options>>.
Currently there is support for CDI and Spring (the latter either via its custom annotations or using the JSR 330 annotations). See <<configuration-options>> for the allowed values of the `componentModel` attribute which are the same as for the `mapstruct.defaultComponentModel` processor option. In both cases the required annotations will be added to the generated mapper implementations classes in order to make the same subject to dependency injection. The following shows an example using CDI: Currently there is support for CDI and Spring (the latter either via its custom annotations or using the JSR 330 annotations). See <<configuration-options>> for the allowed values of the `componentModel` attribute which are the same as for the `mapstruct.defaultComponentModel` processor option and constants are defined in a class `MappingConstants.ComponentModel`. In both cases the required annotations will be added to the generated mapper implementations classes in order to make the same subject to dependency injection. The following shows an example using CDI:
.A mapper using the CDI component model .A mapper using the CDI component model
==== ====
[source, java, linenums] [source, java, linenums]
[subs="verbatim,attributes"] [subs="verbatim,attributes"]
---- ----
@Mapper(componentModel = "cdi") @Mapper(componentModel = MappingConstants.ComponentModel.CDI)
public interface CarMapper { public interface CarMapper {
CarDto carToCarDto(Car car); CarDto carToCarDto(Car car);
@ -110,7 +110,7 @@ This can be done by either providing the injection strategy via `@Mapper` or `@M
[source, java, linenums] [source, java, linenums]
[subs="verbatim,attributes"] [subs="verbatim,attributes"]
---- ----
@Mapper(componentModel = "cdi", uses = EngineMapper.class, injectionStrategy = InjectionStrategy.CONSTRUCTOR) @Mapper(componentModel = MappingConstants.ComponentModel.CDI, uses = EngineMapper.class, injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface CarMapper { public interface CarMapper {
CarDto carToCarDto(Car car); CarDto carToCarDto(Car car);
} }

View File

@ -405,7 +405,7 @@ public class ReferenceMapper {
} }
} }
@Mapper(componentModel = "cdi", uses = ReferenceMapper.class ) @Mapper(componentModel = MappingConstants.ComponentModel.CDI, uses = ReferenceMapper.class )
public interface CarMapper { public interface CarMapper {
Car carDtoToCar(CarDto carDto); Car carDtoToCar(CarDto carDto);

View File

@ -6,10 +6,11 @@
package org.mapstruct.itest.cdi; package org.mapstruct.itest.cdi;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.DecoratedWith; import org.mapstruct.DecoratedWith;
import org.mapstruct.itest.cdi.other.DateMapper; import org.mapstruct.itest.cdi.other.DateMapper;
@Mapper( componentModel = "cdi", uses = DateMapper.class ) @Mapper( componentModel = MappingConstants.ComponentModel.CDI, uses = DateMapper.class )
public interface DecoratedSourceTargetMapper { public interface DecoratedSourceTargetMapper {
Target sourceToTarget(Source source); Target sourceToTarget(Source source);

View File

@ -6,9 +6,10 @@
package org.mapstruct.itest.cdi; package org.mapstruct.itest.cdi;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.itest.cdi.other.DateMapper; import org.mapstruct.itest.cdi.other.DateMapper;
@Mapper(componentModel = "cdi", uses = DateMapper.class) @Mapper(componentModel = MappingConstants.ComponentModel.CDI, uses = DateMapper.class)
public interface SourceTargetMapper { public interface SourceTargetMapper {
Target sourceToTarget(Source source); Target sourceToTarget(Source source);

View File

@ -6,10 +6,11 @@
package org.mapstruct.itest.jsr330; package org.mapstruct.itest.jsr330;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.DecoratedWith; import org.mapstruct.DecoratedWith;
import org.mapstruct.itest.jsr330.other.DateMapper; import org.mapstruct.itest.jsr330.other.DateMapper;
@Mapper(componentModel = "jsr330", uses = DateMapper.class) @Mapper(componentModel = MappingConstants.ComponentModel.JSR330, uses = DateMapper.class)
@DecoratedWith(SourceTargetMapperDecorator.class) @DecoratedWith(SourceTargetMapperDecorator.class)
public interface DecoratedSourceTargetMapper { public interface DecoratedSourceTargetMapper {

View File

@ -6,10 +6,11 @@
package org.mapstruct.itest.jsr330; package org.mapstruct.itest.jsr330;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.DecoratedWith; import org.mapstruct.DecoratedWith;
import org.mapstruct.itest.jsr330.other.DateMapper; import org.mapstruct.itest.jsr330.other.DateMapper;
@Mapper(componentModel = "jsr330", uses = DateMapper.class) @Mapper(componentModel = MappingConstants.ComponentModel.JSR330, uses = DateMapper.class)
@DecoratedWith(SecondSourceTargetMapperDecorator.class) @DecoratedWith(SecondSourceTargetMapperDecorator.class)
public interface SecondDecoratedSourceTargetMapper { public interface SecondDecoratedSourceTargetMapper {

View File

@ -6,9 +6,10 @@
package org.mapstruct.itest.jsr330; package org.mapstruct.itest.jsr330;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.itest.jsr330.other.DateMapper; import org.mapstruct.itest.jsr330.other.DateMapper;
@Mapper(componentModel = "jsr330", uses = DateMapper.class) @Mapper(componentModel = MappingConstants.ComponentModel.JSR330, uses = DateMapper.class)
public interface SourceTargetMapper { public interface SourceTargetMapper {
Target sourceToTarget(Source source); Target sourceToTarget(Source source);

View File

@ -6,10 +6,11 @@
package org.mapstruct.itest.spring; package org.mapstruct.itest.spring;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.DecoratedWith; import org.mapstruct.DecoratedWith;
import org.mapstruct.itest.spring.other.DateMapper; import org.mapstruct.itest.spring.other.DateMapper;
@Mapper( componentModel = "spring", uses = DateMapper.class ) @Mapper( componentModel = MappingConstants.ComponentModel.SPRING, uses = DateMapper.class )
@DecoratedWith( SourceTargetMapperDecorator.class ) @DecoratedWith( SourceTargetMapperDecorator.class )
public interface DecoratedSourceTargetMapper { public interface DecoratedSourceTargetMapper {

View File

@ -6,10 +6,11 @@
package org.mapstruct.itest.spring; package org.mapstruct.itest.spring;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.DecoratedWith; import org.mapstruct.DecoratedWith;
import org.mapstruct.itest.spring.other.DateMapper; import org.mapstruct.itest.spring.other.DateMapper;
@Mapper( componentModel = "spring", uses = DateMapper.class ) @Mapper( componentModel = MappingConstants.ComponentModel.SPRING, uses = DateMapper.class )
@DecoratedWith( SecondSourceTargetMapperDecorator.class ) @DecoratedWith( SecondSourceTargetMapperDecorator.class )
public interface SecondDecoratedSourceTargetMapper { public interface SecondDecoratedSourceTargetMapper {

View File

@ -6,9 +6,10 @@
package org.mapstruct.itest.spring; package org.mapstruct.itest.spring;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.itest.spring.other.DateMapper; import org.mapstruct.itest.spring.other.DateMapper;
@Mapper(componentModel = "spring", uses = DateMapper.class) @Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = DateMapper.class)
public interface SourceTargetMapper { public interface SourceTargetMapper {
Target sourceToTarget(Source source); Target sourceToTarget(Source source);

View File

@ -28,4 +28,23 @@ public final class MappingConstantsGem {
public static final String PREFIX_TRANSFORMATION = "prefix"; public static final String PREFIX_TRANSFORMATION = "prefix";
public static final String STRIP_PREFIX_TRANSFORMATION = "stripPrefix"; public static final String STRIP_PREFIX_TRANSFORMATION = "stripPrefix";
/**
* Gem for the class {@link org.mapstruct.MappingConstants.ComponentModel}
*
*/
public final class ComponentModelGem {
private ComponentModelGem() {
}
public static final String DEFAULT = "default";
public static final String CDI = "cdi";
public static final String SPRING = "spring";
public static final String JSR330 = "jsr330";
}
} }

View File

@ -9,6 +9,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.mapstruct.ap.internal.gem.MappingConstantsGem;
import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.Annotation;
import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.model.Mapper;
@ -23,7 +24,7 @@ public class CdiComponentProcessor extends AnnotationBasedComponentModelProcesso
@Override @Override
protected String getComponentModelIdentifier() { protected String getComponentModelIdentifier() {
return "cdi"; return MappingConstantsGem.ComponentModelGem.CDI;
} }
@Override @Override

View File

@ -9,6 +9,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.mapstruct.ap.internal.gem.MappingConstantsGem;
import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.Annotation;
import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.model.Mapper;
@ -23,7 +24,7 @@ import org.mapstruct.ap.internal.model.Mapper;
public class Jsr330ComponentProcessor extends AnnotationBasedComponentModelProcessor { public class Jsr330ComponentProcessor extends AnnotationBasedComponentModelProcessor {
@Override @Override
protected String getComponentModelIdentifier() { protected String getComponentModelIdentifier() {
return "jsr330"; return MappingConstantsGem.ComponentModelGem.JSR330;
} }
@Override @Override

View File

@ -11,6 +11,7 @@ import javax.lang.model.element.TypeElement;
import javax.tools.FileObject; import javax.tools.FileObject;
import javax.tools.StandardLocation; import javax.tools.StandardLocation;
import org.mapstruct.ap.internal.gem.MappingConstantsGem;
import org.mapstruct.ap.internal.model.GeneratedType; import org.mapstruct.ap.internal.model.GeneratedType;
import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.model.Mapper;
import org.mapstruct.ap.internal.model.ServicesEntry; import org.mapstruct.ap.internal.model.ServicesEntry;
@ -38,7 +39,7 @@ public class MapperServiceProcessor implements ModelElementProcessor<Mapper, Vo
String componentModel = String componentModel =
MapperOptions.getInstanceOn( mapperTypeElement, context.getOptions() ).componentModel( ); MapperOptions.getInstanceOn( mapperTypeElement, context.getOptions() ).componentModel( );
spiGenerationNeeded = "default".equals( componentModel ); spiGenerationNeeded = MappingConstantsGem.ComponentModelGem.DEFAULT.equals( componentModel );
} }
if ( !context.isErroneous() && spiGenerationNeeded && mapper.hasCustomImplementation() ) { if ( !context.isErroneous() && spiGenerationNeeded && mapper.hasCustomImplementation() ) {

View File

@ -10,6 +10,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.mapstruct.ap.internal.gem.MappingConstantsGem;
import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.Annotation;
import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.model.Mapper;
@ -24,7 +25,7 @@ import org.mapstruct.ap.internal.model.Mapper;
public class SpringComponentProcessor extends AnnotationBasedComponentModelProcessor { public class SpringComponentProcessor extends AnnotationBasedComponentModelProcessor {
@Override @Override
protected String getComponentModelIdentifier() { protected String getComponentModelIdentifier() {
return "spring"; return MappingConstantsGem.ComponentModelGem.SPRING;
} }
@Override @Override

View File

@ -7,11 +7,13 @@ package org.mapstruct.ap.test.bugs._1395;
import org.mapstruct.InjectionStrategy; import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
/** /**
* @author Filip Hrisafov * @author Filip Hrisafov
*/ */
@Mapper(injectionStrategy = InjectionStrategy.CONSTRUCTOR, componentModel = "spring", uses = NotUsedService.class) @Mapper(injectionStrategy = InjectionStrategy.CONSTRUCTOR, componentModel = MappingConstants.ComponentModel.SPRING,
uses = NotUsedService.class)
public interface Issue1395Mapper { public interface Issue1395Mapper {
Target map(Source source); Target map(Source source);

View File

@ -10,6 +10,7 @@ import javax.tools.Diagnostic.Kind;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
@ -30,7 +31,7 @@ import org.springframework.stereotype.Component;
Poodle.class, Poodle.class,
Config.class }) Config.class })
@ProcessorOptions({ @ProcessorOptions({
@ProcessorOption(name = "mapstruct.defaultComponentModel", value = "spring"), @ProcessorOption(name = "mapstruct.defaultComponentModel", value = MappingConstants.ComponentModel.SPRING),
@ProcessorOption(name = "mapstruct.unmappedTargetPolicy", value = "ignore") }) @ProcessorOption(name = "mapstruct.unmappedTargetPolicy", value = "ignore") })
public class Issue880Test { public class Issue880Test {
@Rule @Rule
@ -40,7 +41,7 @@ public class Issue880Test {
@ExpectedCompilationOutcome( @ExpectedCompilationOutcome(
value = CompilationResult.SUCCEEDED, value = CompilationResult.SUCCEEDED,
diagnostics = @Diagnostic(kind = Kind.WARNING, diagnostics = @Diagnostic(kind = Kind.WARNING,
type = UsesConfigFromAnnotationMapper.class, line = 16, type = UsesConfigFromAnnotationMapper.class, line = 17,
message = "Unmapped target property: \"core\".")) message = "Unmapped target property: \"core\"."))
public void compilationSucceedsAndAppliesCorrectComponentModel() { public void compilationSucceedsAndAppliesCorrectComponentModel() {
generatedSource.forMapper( UsesConfigFromAnnotationMapper.class ).containsNoImportFor( Component.class ); generatedSource.forMapper( UsesConfigFromAnnotationMapper.class ).containsNoImportFor( Component.class );

View File

@ -6,12 +6,13 @@
package org.mapstruct.ap.test.bugs._880; package org.mapstruct.ap.test.bugs._880;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
* *
*/ */
@Mapper(componentModel = "default", config = Config.class) @Mapper(componentModel = MappingConstants.ComponentModel.DEFAULT, config = Config.class)
public interface UsesConfigFromAnnotationMapper { public interface UsesConfigFromAnnotationMapper {
Poodle metamorph(Object essence); Poodle metamorph(Object essence);
} }

View File

@ -8,12 +8,13 @@ package org.mapstruct.ap.test.decorator.jsr330;
import org.mapstruct.DecoratedWith; import org.mapstruct.DecoratedWith;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.decorator.Address; import org.mapstruct.ap.test.decorator.Address;
import org.mapstruct.ap.test.decorator.AddressDto; import org.mapstruct.ap.test.decorator.AddressDto;
import org.mapstruct.ap.test.decorator.Person; import org.mapstruct.ap.test.decorator.Person;
import org.mapstruct.ap.test.decorator.PersonDto; import org.mapstruct.ap.test.decorator.PersonDto;
@Mapper(componentModel = "jsr330") @Mapper(componentModel = MappingConstants.ComponentModel.JSR330)
@DecoratedWith(PersonMapperDecorator.class) @DecoratedWith(PersonMapperDecorator.class)
public interface PersonMapper { public interface PersonMapper {

View File

@ -9,12 +9,13 @@ import org.mapstruct.DecoratedWith;
import org.mapstruct.InjectionStrategy; import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.decorator.Address; import org.mapstruct.ap.test.decorator.Address;
import org.mapstruct.ap.test.decorator.AddressDto; import org.mapstruct.ap.test.decorator.AddressDto;
import org.mapstruct.ap.test.decorator.Person; import org.mapstruct.ap.test.decorator.Person;
import org.mapstruct.ap.test.decorator.PersonDto; import org.mapstruct.ap.test.decorator.PersonDto;
@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR) @Mapper(componentModel = MappingConstants.ComponentModel.SPRING, injectionStrategy = InjectionStrategy.CONSTRUCTOR)
@DecoratedWith(PersonMapperDecorator.class) @DecoratedWith(PersonMapperDecorator.class)
public interface PersonMapper { public interface PersonMapper {

View File

@ -9,12 +9,13 @@ import org.mapstruct.DecoratedWith;
import org.mapstruct.InjectionStrategy; import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.decorator.Address; import org.mapstruct.ap.test.decorator.Address;
import org.mapstruct.ap.test.decorator.AddressDto; import org.mapstruct.ap.test.decorator.AddressDto;
import org.mapstruct.ap.test.decorator.Person; import org.mapstruct.ap.test.decorator.Person;
import org.mapstruct.ap.test.decorator.PersonDto; import org.mapstruct.ap.test.decorator.PersonDto;
@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.FIELD) @Mapper(componentModel = MappingConstants.ComponentModel.SPRING, injectionStrategy = InjectionStrategy.FIELD)
@DecoratedWith(PersonMapperDecorator.class) @DecoratedWith(PersonMapperDecorator.class)
public interface PersonMapper { public interface PersonMapper {

View File

@ -6,11 +6,12 @@
package org.mapstruct.ap.test.destination; package org.mapstruct.ap.test.destination;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
/** /**
* @author Christophe Labouisse on 27/05/2015. * @author Christophe Labouisse on 27/05/2015.
*/ */
@Mapper(implementationName = "<CLASS_NAME>Jsr330Impl", componentModel = "jsr330") @Mapper(implementationName = "<CLASS_NAME>Jsr330Impl", componentModel = MappingConstants.ComponentModel.JSR330)
public interface DestinationClassNameWithJsr330Mapper { public interface DestinationClassNameWithJsr330Mapper {
String intToString(Integer source); String intToString(Integer source);
} }

View File

@ -30,4 +30,13 @@ public class ConstantTest {
assertThat( MappingConstants.STRIP_PREFIX_TRANSFORMATION ) assertThat( MappingConstants.STRIP_PREFIX_TRANSFORMATION )
.isEqualTo( MappingConstantsGem.STRIP_PREFIX_TRANSFORMATION ); .isEqualTo( MappingConstantsGem.STRIP_PREFIX_TRANSFORMATION );
} }
@Test
public void componentModelContantsShouldBeEqual() {
assertThat( MappingConstants.ComponentModel.DEFAULT )
.isEqualTo( MappingConstantsGem.ComponentModelGem.DEFAULT );
assertThat( MappingConstants.ComponentModel.CDI ).isEqualTo( MappingConstantsGem.ComponentModelGem.CDI );
assertThat( MappingConstants.ComponentModel.SPRING ).isEqualTo( MappingConstantsGem.ComponentModelGem.SPRING );
assertThat( MappingConstants.ComponentModel.JSR330 ).isEqualTo( MappingConstantsGem.ComponentModelGem.JSR330 );
}
} }

View File

@ -8,6 +8,7 @@ package org.mapstruct.ap.test.imports;
import java.util.Date; import java.util.Date;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.imports.referenced.Source; import org.mapstruct.ap.test.imports.referenced.Source;
import org.mapstruct.ap.test.imports.referenced.Target; import org.mapstruct.ap.test.imports.referenced.Target;
import org.mapstruct.ap.test.imports.to.Foo; import org.mapstruct.ap.test.imports.to.Foo;
@ -16,7 +17,7 @@ import org.mapstruct.factory.Mappers;
/** /**
* @author Gunnar Morling * @author Gunnar Morling
*/ */
@Mapper(componentModel = "jsr330") @Mapper(componentModel = MappingConstants.ComponentModel.JSR330)
public interface SourceTargetMapper { public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );

View File

@ -6,13 +6,15 @@
package org.mapstruct.ap.test.injectionstrategy.jsr330._default; package org.mapstruct.ap.test.injectionstrategy.jsr330._default;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/** /**
* @author Andrei Arlou * @author Andrei Arlou
*/ */
@Mapper(componentModel = "jsr330", uses = GenderJsr330DefaultCompileOptionFieldMapper.class) @Mapper(componentModel = MappingConstants.ComponentModel.JSR330,
uses = GenderJsr330DefaultCompileOptionFieldMapper.class)
public interface CustomerJsr330DefaultCompileOptionFieldMapper { public interface CustomerJsr330DefaultCompileOptionFieldMapper {
CustomerDto asTarget(CustomerEntity customerEntity); CustomerDto asTarget(CustomerEntity customerEntity);

View File

@ -6,6 +6,7 @@
package org.mapstruct.ap.test.injectionstrategy.jsr330._default; package org.mapstruct.ap.test.injectionstrategy.jsr330._default;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ValueMapping; import org.mapstruct.ValueMapping;
import org.mapstruct.ValueMappings; import org.mapstruct.ValueMappings;
import org.mapstruct.ap.test.injectionstrategy.shared.Gender; import org.mapstruct.ap.test.injectionstrategy.shared.Gender;
@ -14,7 +15,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto;
/** /**
* @author Andrei Arlou * @author Andrei Arlou
*/ */
@Mapper(componentModel = "jsr330") @Mapper(componentModel = MappingConstants.ComponentModel.JSR330)
public interface GenderJsr330DefaultCompileOptionFieldMapper { public interface GenderJsr330DefaultCompileOptionFieldMapper {
@ValueMappings({ @ValueMappings({

View File

@ -7,13 +7,14 @@ package org.mapstruct.ap.test.injectionstrategy.jsr330.compileoptionconstructor;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/** /**
* @author Andrei Arlou * @author Andrei Arlou
*/ */
@Mapper( componentModel = "jsr330", @Mapper( componentModel = MappingConstants.ComponentModel.JSR330,
uses = GenderJsr330CompileOptionConstructorMapper.class ) uses = GenderJsr330CompileOptionConstructorMapper.class )
public interface CustomerJsr330CompileOptionConstructorMapper { public interface CustomerJsr330CompileOptionConstructorMapper {

View File

@ -6,6 +6,7 @@
package org.mapstruct.ap.test.injectionstrategy.jsr330.compileoptionconstructor; package org.mapstruct.ap.test.injectionstrategy.jsr330.compileoptionconstructor;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ValueMapping; import org.mapstruct.ValueMapping;
import org.mapstruct.ValueMappings; import org.mapstruct.ValueMappings;
import org.mapstruct.ap.test.injectionstrategy.shared.Gender; import org.mapstruct.ap.test.injectionstrategy.shared.Gender;
@ -14,7 +15,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto;
/** /**
* @author Andrei Arlou * @author Andrei Arlou
*/ */
@Mapper(componentModel = "jsr330") @Mapper(componentModel = MappingConstants.ComponentModel.JSR330)
public interface GenderJsr330CompileOptionConstructorMapper { public interface GenderJsr330CompileOptionConstructorMapper {
@ValueMappings({ @ValueMappings({

View File

@ -7,10 +7,12 @@ package org.mapstruct.ap.test.injectionstrategy.jsr330.constructor;
import org.mapstruct.InjectionStrategy; import org.mapstruct.InjectionStrategy;
import org.mapstruct.MapperConfig; import org.mapstruct.MapperConfig;
import org.mapstruct.MappingConstants;
/** /**
* @author Filip Hrisafov * @author Filip Hrisafov
*/ */
@MapperConfig(componentModel = "jsr330", injectionStrategy = InjectionStrategy.CONSTRUCTOR) @MapperConfig(componentModel = MappingConstants.ComponentModel.JSR330,
injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface ConstructorJsr330Config { public interface ConstructorJsr330Config {
} }

View File

@ -8,13 +8,14 @@ package org.mapstruct.ap.test.injectionstrategy.jsr330.constructor;
import org.mapstruct.InjectionStrategy; import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/** /**
* @author Kevin Grüneberg * @author Kevin Grüneberg
*/ */
@Mapper( componentModel = "jsr330", @Mapper( componentModel = MappingConstants.ComponentModel.JSR330,
uses = GenderJsr330ConstructorMapper.class, uses = GenderJsr330ConstructorMapper.class,
injectionStrategy = InjectionStrategy.CONSTRUCTOR ) injectionStrategy = InjectionStrategy.CONSTRUCTOR )
public interface CustomerJsr330ConstructorMapper { public interface CustomerJsr330ConstructorMapper {

View File

@ -7,13 +7,15 @@ package org.mapstruct.ap.test.injectionstrategy.jsr330.field;
import org.mapstruct.InjectionStrategy; import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/** /**
* @author Kevin Grüneberg * @author Kevin Grüneberg
*/ */
@Mapper(componentModel = "jsr330", uses = GenderJsr330FieldMapper.class, injectionStrategy = InjectionStrategy.FIELD) @Mapper(componentModel = MappingConstants.ComponentModel.JSR330, uses = GenderJsr330FieldMapper.class,
injectionStrategy = InjectionStrategy.FIELD)
public interface CustomerJsr330FieldMapper { public interface CustomerJsr330FieldMapper {
CustomerDto asTarget(CustomerEntity customerEntity); CustomerDto asTarget(CustomerEntity customerEntity);

View File

@ -7,10 +7,11 @@ package org.mapstruct.ap.test.injectionstrategy.jsr330.field;
import org.mapstruct.InjectionStrategy; import org.mapstruct.InjectionStrategy;
import org.mapstruct.MapperConfig; import org.mapstruct.MapperConfig;
import org.mapstruct.MappingConstants;
/** /**
* @author Filip Hrisafov * @author Filip Hrisafov
*/ */
@MapperConfig(componentModel = "jsr330", injectionStrategy = InjectionStrategy.FIELD) @MapperConfig(componentModel = MappingConstants.ComponentModel.JSR330, injectionStrategy = InjectionStrategy.FIELD)
public interface FieldJsr330Config { public interface FieldJsr330Config {
} }

View File

@ -6,13 +6,14 @@
package org.mapstruct.ap.test.injectionstrategy.spring._default; package org.mapstruct.ap.test.injectionstrategy.spring._default;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/** /**
* @author Filip Hrisafov * @author Filip Hrisafov
*/ */
@Mapper(componentModel = "spring", uses = GenderSpringDefaultMapper.class ) @Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = GenderSpringDefaultMapper.class )
public interface CustomerSpringDefaultMapper { public interface CustomerSpringDefaultMapper {
CustomerDto asTarget(CustomerEntity customerEntity); CustomerDto asTarget(CustomerEntity customerEntity);

View File

@ -6,6 +6,7 @@
package org.mapstruct.ap.test.injectionstrategy.spring._default; package org.mapstruct.ap.test.injectionstrategy.spring._default;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ValueMapping; import org.mapstruct.ValueMapping;
import org.mapstruct.ValueMappings; import org.mapstruct.ValueMappings;
import org.mapstruct.ap.test.injectionstrategy.shared.Gender; import org.mapstruct.ap.test.injectionstrategy.shared.Gender;
@ -14,7 +15,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto;
/** /**
* @author Filip Hrisafov * @author Filip Hrisafov
*/ */
@Mapper(componentModel = "spring") @Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface GenderSpringDefaultMapper { public interface GenderSpringDefaultMapper {
@ValueMappings({ @ValueMappings({

View File

@ -6,13 +6,14 @@
package org.mapstruct.ap.test.injectionstrategy.spring.compileoptionconstructor; package org.mapstruct.ap.test.injectionstrategy.spring.compileoptionconstructor;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity;
/** /**
* @author Andrei Arlou * @author Andrei Arlou
*/ */
@Mapper(componentModel = "spring", @Mapper(componentModel = MappingConstants.ComponentModel.SPRING,
uses = { CustomerSpringCompileOptionConstructorMapper.class, GenderSpringCompileOptionConstructorMapper.class }, uses = { CustomerSpringCompileOptionConstructorMapper.class, GenderSpringCompileOptionConstructorMapper.class },
disableSubMappingMethodsGeneration = true) disableSubMappingMethodsGeneration = true)
public interface CustomerRecordSpringCompileOptionConstructorMapper { public interface CustomerRecordSpringCompileOptionConstructorMapper {

View File

@ -7,13 +7,14 @@ package org.mapstruct.ap.test.injectionstrategy.spring.compileoptionconstructor;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/** /**
* @author Andrei Arlou * @author Andrei Arlou
*/ */
@Mapper( componentModel = "spring", @Mapper( componentModel = MappingConstants.ComponentModel.SPRING,
uses = GenderSpringCompileOptionConstructorMapper.class) uses = GenderSpringCompileOptionConstructorMapper.class)
public interface CustomerSpringCompileOptionConstructorMapper { public interface CustomerSpringCompileOptionConstructorMapper {

View File

@ -6,6 +6,7 @@
package org.mapstruct.ap.test.injectionstrategy.spring.compileoptionconstructor; package org.mapstruct.ap.test.injectionstrategy.spring.compileoptionconstructor;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ValueMapping; import org.mapstruct.ValueMapping;
import org.mapstruct.ValueMappings; import org.mapstruct.ValueMappings;
import org.mapstruct.ap.test.injectionstrategy.shared.Gender; import org.mapstruct.ap.test.injectionstrategy.shared.Gender;
@ -14,7 +15,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto;
/** /**
* @author Andrei Arlou * @author Andrei Arlou
*/ */
@Mapper(componentModel = "spring") @Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface GenderSpringCompileOptionConstructorMapper { public interface GenderSpringCompileOptionConstructorMapper {
@ValueMappings({ @ValueMappings({

View File

@ -7,10 +7,12 @@ package org.mapstruct.ap.test.injectionstrategy.spring.constructor;
import org.mapstruct.InjectionStrategy; import org.mapstruct.InjectionStrategy;
import org.mapstruct.MapperConfig; import org.mapstruct.MapperConfig;
import org.mapstruct.MappingConstants;
/** /**
* @author Filip Hrisafov * @author Filip Hrisafov
*/ */
@MapperConfig(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR) @MapperConfig(componentModel = MappingConstants.ComponentModel.SPRING,
injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface ConstructorSpringConfig { public interface ConstructorSpringConfig {
} }

View File

@ -7,13 +7,14 @@ package org.mapstruct.ap.test.injectionstrategy.spring.constructor;
import org.mapstruct.InjectionStrategy; import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity;
/** /**
* @author Kevin Grüneberg * @author Kevin Grüneberg
*/ */
@Mapper(componentModel = "spring", @Mapper(componentModel = MappingConstants.ComponentModel.SPRING,
uses = { CustomerSpringConstructorMapper.class, GenderSpringConstructorMapper.class }, uses = { CustomerSpringConstructorMapper.class, GenderSpringConstructorMapper.class },
injectionStrategy = InjectionStrategy.CONSTRUCTOR, injectionStrategy = InjectionStrategy.CONSTRUCTOR,
disableSubMappingMethodsGeneration = true) disableSubMappingMethodsGeneration = true)

View File

@ -8,13 +8,14 @@ package org.mapstruct.ap.test.injectionstrategy.spring.constructor;
import org.mapstruct.InjectionStrategy; import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/** /**
* @author Kevin Grüneberg * @author Kevin Grüneberg
*/ */
@Mapper( componentModel = "spring", @Mapper( componentModel = MappingConstants.ComponentModel.SPRING,
uses = GenderSpringConstructorMapper.class, uses = GenderSpringConstructorMapper.class,
injectionStrategy = InjectionStrategy.CONSTRUCTOR ) injectionStrategy = InjectionStrategy.CONSTRUCTOR )
public interface CustomerSpringConstructorMapper { public interface CustomerSpringConstructorMapper {

View File

@ -7,13 +7,15 @@ package org.mapstruct.ap.test.injectionstrategy.spring.field;
import org.mapstruct.InjectionStrategy; import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto;
import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity;
/** /**
* @author Kevin Grüneberg * @author Kevin Grüneberg
*/ */
@Mapper(componentModel = "spring", uses = GenderSpringFieldMapper.class, injectionStrategy = InjectionStrategy.FIELD) @Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = GenderSpringFieldMapper.class,
injectionStrategy = InjectionStrategy.FIELD)
public interface CustomerSpringFieldMapper { public interface CustomerSpringFieldMapper {
CustomerDto asTarget(CustomerEntity customerEntity); CustomerDto asTarget(CustomerEntity customerEntity);

View File

@ -7,10 +7,11 @@ package org.mapstruct.ap.test.injectionstrategy.spring.field;
import org.mapstruct.InjectionStrategy; import org.mapstruct.InjectionStrategy;
import org.mapstruct.MapperConfig; import org.mapstruct.MapperConfig;
import org.mapstruct.MappingConstants;
/** /**
* @author Filip Hrisafov * @author Filip Hrisafov
*/ */
@MapperConfig(componentModel = "spring", injectionStrategy = InjectionStrategy.FIELD) @MapperConfig(componentModel = MappingConstants.ComponentModel.SPRING, injectionStrategy = InjectionStrategy.FIELD)
public interface FieldSpringConfig { public interface FieldSpringConfig {
} }

View File

@ -6,6 +6,7 @@
package org.mapstruct.ap.test.references.samename; package org.mapstruct.ap.test.references.samename;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ap.test.references.samename.a.CustomMapper; import org.mapstruct.ap.test.references.samename.a.CustomMapper;
import org.mapstruct.ap.test.references.samename.model.Source; import org.mapstruct.ap.test.references.samename.model.Source;
import org.mapstruct.ap.test.references.samename.model.Target; import org.mapstruct.ap.test.references.samename.model.Target;
@ -15,7 +16,7 @@ import org.mapstruct.factory.Mappers;
* @author Gunnar Morling * @author Gunnar Morling
*/ */
@Mapper( @Mapper(
componentModel = "jsr330", componentModel = MappingConstants.ComponentModel.JSR330,
uses = { uses = {
CustomMapper.class, CustomMapper.class,
org.mapstruct.ap.test.references.samename.b.CustomMapper.class org.mapstruct.ap.test.references.samename.b.CustomMapper.class