This commit is contained in:
Gunnar Morling 2015-02-24 23:46:18 +01:00
parent ec614a6e25
commit bbeaa2117c
27 changed files with 96 additions and 104 deletions

View File

@ -79,7 +79,8 @@ public @interface MapMapping {
/** /**
* Specifies the type of the key to be used in the result of the mapping method in case multiple mapping * Specifies the type of the key to be used in the result of the mapping method in case multiple mapping
* methods qualify. * methods qualify.
* * *
*
* @return the resultType to select * @return the resultType to select
*/ */
Class<?> keyTargetType() default void.class; Class<?> keyTargetType() default void.class;
@ -87,7 +88,8 @@ public @interface MapMapping {
/** /**
* Specifies the type of the value to be used in the result of the mapping method in case multiple mapping * Specifies the type of the value to be used in the result of the mapping method in case multiple mapping
* methods qualify. * methods qualify.
* * *
*
* @return the resultType to select * @return the resultType to select
*/ */
Class<?> valueTargetType() default void.class; Class<?> valueTargetType() default void.class;

View File

@ -55,6 +55,7 @@ public class Mappers {
* *
* @param clazz The type of the mapper to return. * @param clazz The type of the mapper to return.
* @param <T> The type of the mapper to create. * @param <T> The type of the mapper to create.
*
* @return An instance of the given mapper type. * @return An instance of the given mapper type.
*/ */
public static <T> T getMapper(Class<T> clazz) { public static <T> T getMapper(Class<T> clazz) {

View File

@ -412,7 +412,8 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
* per the source/target type and optionally the name given via {@code @InheritInverseConfiguration}). * per the source/target type and optionally the name given via {@code @InheritInverseConfiguration}).
*/ */
private MappingOptions getInverseMappingOptions(List<SourceMethod> rawMethods, SourceMethod method, private MappingOptions getInverseMappingOptions(List<SourceMethod> rawMethods, SourceMethod method,
List<SourceMethod> initializingMethods, MapperConfiguration mapperConfig) { List<SourceMethod> initializingMethods,
MapperConfiguration mapperConfig) {
SourceMethod resultMethod = null; SourceMethod resultMethod = null;
InheritInverseConfigurationPrism reversePrism = InheritInverseConfigurationPrism.getInstanceOn( InheritInverseConfigurationPrism reversePrism = InheritInverseConfigurationPrism.getInstanceOn(
method.getExecutable() method.getExecutable()

View File

@ -29,8 +29,6 @@ import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeMirror;
import org.mapstruct.Mapper;
import org.mapstruct.MapperConfig;
import org.mapstruct.ap.option.ReportingPolicy; import org.mapstruct.ap.option.ReportingPolicy;
import org.mapstruct.ap.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.prism.CollectionMappingStrategyPrism;
import org.mapstruct.ap.prism.MapperConfigPrism; import org.mapstruct.ap.prism.MapperConfigPrism;
@ -40,12 +38,12 @@ import org.mapstruct.ap.prism.NullValueMappingPrism;
import org.mapstruct.ap.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.prism.NullValueMappingStrategyPrism;
/** /**
* Provides an aggregated view to the settings given via {@link Mapper} and {@link MapperConfig} for a specific mapper * Provides an aggregated view to the settings given via {@link org.mapstruct.Mapper} and
* class. * {@link org.mapstruct.MapperConfig} for a specific mapper class.
* <p> * <p>
* Settings given via {@code Mapper} will generally take precedence over settings inherited from a referenced config * Settings given via {@code Mapper} will generally take precedence over settings inherited from a referenced config
* class. The lists of referenced mappers given via {@link Mapper#uses()} and {@link MapperConfig#uses() } will be * class. The lists of referenced mappers given via {@link org.mapstruct.Mapper#uses()} and
* merged. * {@link org.mapstruct.MapperConfig#uses() } will be merged.
* *
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.inheritfromconfig;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*
*/ */
public abstract class BaseVehicleDto { public abstract class BaseVehicleDto {
private long id; private long id;

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.inheritfromconfig;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*
*/ */
public abstract class BaseVehicleEntity { public abstract class BaseVehicleEntity {
private long primaryKey; private long primaryKey;

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.inheritfromconfig;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*
*/ */
public class CarDto extends BaseVehicleDto { public class CarDto extends BaseVehicleDto {
private String colour; private String colour;

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.inheritfromconfig;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*
*/ */
public class CarEntity extends BaseVehicleEntity { public class CarEntity extends BaseVehicleEntity {
private String color; private String color;

View File

@ -28,7 +28,6 @@ import org.mapstruct.factory.Mappers;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*
*/ */
@Mapper( @Mapper(
config = AutoInheritedConfig.class config = AutoInheritedConfig.class

View File

@ -27,7 +27,6 @@ import org.mapstruct.factory.Mappers;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*
*/ */
@Mapper( @Mapper(
config = AutoInheritedConfig.class, config = AutoInheritedConfig.class,

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.inheritfromconfig;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*
*/ */
public class CarWithDriverEntity extends CarEntity { public class CarWithDriverEntity extends CarEntity {
private String driverName; private String driverName;

View File

@ -24,7 +24,6 @@ import org.mapstruct.factory.Mappers;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*
*/ */
@Mapper( @Mapper(
config = AutoInheritedDriverConfig.class config = AutoInheritedDriverConfig.class

View File

@ -20,7 +20,6 @@ package org.mapstruct.ap.test.inheritfromconfig;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*
*/ */
public class DriverDto { public class DriverDto {
private String name; private String name;

View File

@ -25,7 +25,6 @@ import org.mapstruct.factory.Mappers;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*
*/ */
@Mapper( @Mapper(
config = Erroneous1Config.class config = Erroneous1Config.class

View File

@ -27,7 +27,6 @@ import org.mapstruct.factory.Mappers;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*
*/ */
@Mapper( @Mapper(
config = AutoInheritedConfig.class config = AutoInheritedConfig.class

View File

@ -18,6 +18,8 @@
*/ */
package org.mapstruct.ap.test.inheritfromconfig; package org.mapstruct.ap.test.inheritfromconfig;
import static org.fest.assertions.Assertions.assertThat;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import org.junit.Test; import org.junit.Test;
@ -29,11 +31,8 @@ import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* @author Andreas Gudian * @author Andreas Gudian
*
*/ */
@RunWith(AnnotationProcessorTestRunner.class) @RunWith(AnnotationProcessorTestRunner.class)
@WithClasses({ @WithClasses({
@ -43,7 +42,8 @@ import static org.fest.assertions.Assertions.assertThat;
CarEntity.class, CarEntity.class,
CarMapperWithAutoInheritance.class, CarMapperWithAutoInheritance.class,
CarMapperWithExplicitInheritance.class, CarMapperWithExplicitInheritance.class,
AutoInheritedConfig.class } ) AutoInheritedConfig.class
})
@IssueKey("168") @IssueKey("168")
public class InheritFromConfigTest { public class InheritFromConfigTest {
@ -149,7 +149,8 @@ public class InheritFromConfigTest {
DriverDto.class, DriverDto.class,
CarWithDriverEntity.class, CarWithDriverEntity.class,
CarWithDriverMapperWithAutoInheritance.class, CarWithDriverMapperWithAutoInheritance.class,
AutoInheritedDriverConfig.class } ) AutoInheritedDriverConfig.class
})
public void autoInheritedFromMultipleSources() { public void autoInheritedFromMultipleSources() {
CarDto carDto = newTestDto(); CarDto carDto = newTestDto();
DriverDto driverDto = new DriverDto(); DriverDto driverDto = new DriverDto();
@ -169,25 +170,25 @@ public class InheritFromConfigTest {
diagnostics = { diagnostics = {
@Diagnostic(type = Erroneous1Mapper.class, @Diagnostic(type = Erroneous1Mapper.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 37, line = 36,
messageRegExp = "More than one configuration prototype method is applicable. Use @InheritConfiguration" messageRegExp = "More than one configuration prototype method is applicable. Use @InheritConfiguration"
+ " to select one of them explicitly:" + " to select one of them explicitly:"
+ " .*BaseVehicleEntity baseDtoToEntity\\(.*BaseVehicleDto dto\\)," + " .*BaseVehicleEntity baseDtoToEntity\\(.*BaseVehicleDto dto\\),"
+ " .*BaseVehicleEntity anythingToEntity\\(java.lang.Object anyting\\)\\."), + " .*BaseVehicleEntity anythingToEntity\\(java.lang.Object anyting\\)\\."),
@Diagnostic(type = Erroneous1Mapper.class, @Diagnostic(type = Erroneous1Mapper.class,
kind = Kind.WARNING, kind = Kind.WARNING,
line = 37, line = 36,
messageRegExp = "Unmapped target properties: \"auditTrail, primaryKey\"\\."), messageRegExp = "Unmapped target properties: \"auditTrail, primaryKey\"\\."),
@Diagnostic(type = Erroneous1Mapper.class, @Diagnostic(type = Erroneous1Mapper.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 43, line = 42,
messageRegExp = "More than one configuration prototype method is applicable. Use @InheritConfiguration" messageRegExp = "More than one configuration prototype method is applicable. Use @InheritConfiguration"
+ " to select one of them explicitly:" + " to select one of them explicitly:"
+ " .*BaseVehicleEntity baseDtoToEntity\\(.*BaseVehicleDto dto\\)," + " .*BaseVehicleEntity baseDtoToEntity\\(.*BaseVehicleDto dto\\),"
+ " .*BaseVehicleEntity anythingToEntity\\(java.lang.Object anyting\\)\\."), + " .*BaseVehicleEntity anythingToEntity\\(java.lang.Object anyting\\)\\."),
@Diagnostic(type = Erroneous1Mapper.class, @Diagnostic(type = Erroneous1Mapper.class,
kind = Kind.WARNING, kind = Kind.WARNING,
line = 43, line = 42,
messageRegExp = "Unmapped target property: \"primaryKey\"\\.") messageRegExp = "Unmapped target property: \"primaryKey\"\\.")
} }
) )
@ -202,7 +203,7 @@ public class InheritFromConfigTest {
diagnostics = { diagnostics = {
@Diagnostic(type = Erroneous2Mapper.class, @Diagnostic(type = Erroneous2Mapper.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 39, line = 38,
messageRegExp = "Cycle detected while evaluating inherited configurations. Inheritance path:" messageRegExp = "Cycle detected while evaluating inherited configurations. Inheritance path:"
+ " .*CarEntity toCarEntity1\\(.*CarDto carDto\\)" + " .*CarEntity toCarEntity1\\(.*CarDto carDto\\)"
+ " -> .*CarEntity toCarEntity2\\(.*CarDto carDto\\)" + " -> .*CarEntity toCarEntity2\\(.*CarDto carDto\\)"