#102 addressing some comments (config iso mapperConfig, removing TYPE.PACKAGE from annotation, adding class javadoc, renaming MapperSettings to more logical MapperConfig)

This commit is contained in:
sjaakd 2014-04-01 23:35:00 +02:00 committed by Gunnar Morling
parent c374f7c818
commit af9074ce13
9 changed files with 31 additions and 24 deletions

View File

@ -45,7 +45,7 @@ public @interface Mapper {
/**
* How unmapped properties of the target type of a mapping should be
* reported. The method overrides an unmappedTargetPolicy set in a central
* configuration set by {@link #mapperConfig() }
* configuration set by {@link #config() }
*
* @return The reporting policy for unmapped target properties.
*/
@ -68,7 +68,7 @@ public @interface Mapper {
* can be retrieved via {@code @Inject}</li>
* </ul>
* The method overrides an unmappedTargetPolicy set in a central configuration set
* by {@link #mapperConfig() }
* by {@link #config() }
* @return The component model for the generated mapper.
*/
@ -79,6 +79,6 @@ public @interface Mapper {
*
* @return a centralized class with {@link MapperConfig} annotation.
*/
Class<?> mapperConfig() default void.class;
Class<?> config() default void.class;
}

View File

@ -26,14 +26,14 @@ import java.lang.annotation.Target;
import org.mapstruct.factory.Mappers;
/**
* Marks a class-, interface-, enum declaration or package declaration as (common) configuration.
* Marks a class-, interface-, enum declaration as (common) configuration.
*
* The {@link #unmappedTargetPolicy() } and {@link #componentModel() } an be overruled by a specific {@link Mapper}
* The {@link #unmappedTargetPolicy() } and {@link #componentModel() } can be overruled by a specific {@link Mapper}
* annotation. {@link #uses() } will be used in addition to what is specified in the {@link Mapper} annotation.
*
* @author Sjaak Derksen
*/
@Target( { ElementType.TYPE, ElementType.PACKAGE } )
@Target( { ElementType.TYPE } )
@Retention(RetentionPolicy.SOURCE)
public @interface MapperConfig {
@ -50,7 +50,7 @@ public @interface MapperConfig {
*
* @return The reporting policy for unmapped target properties.
*/
ReportingPolicy unmappedTargetPolicy() default ReportingPolicy.DEFAULT;
ReportingPolicy unmappedTargetPolicy() default ReportingPolicy.WARN;
/**
* Specifies the component model to which the generated mapper should

View File

@ -27,7 +27,7 @@ import org.mapstruct.ap.model.Mapper;
import org.mapstruct.ap.model.MapperReference;
import org.mapstruct.ap.model.common.TypeFactory;
import org.mapstruct.ap.option.OptionsHelper;
import org.mapstruct.ap.util.MapperSettings;
import org.mapstruct.ap.util.MapperConfig;
/**
* An {@link ModelElementProcessor} which converts the given {@link Mapper}
@ -45,7 +45,7 @@ public abstract class AnnotationBasedComponentModelProcessor implements ModelEle
public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, Mapper mapper) {
this.typeFactory = context.getTypeFactory();
String componentModel = MapperSettings.getInstanceOn( mapperTypeElement ).componentModel();
String componentModel = MapperConfig.getInstanceOn( mapperTypeElement ).componentModel();
String effectiveComponentModel = OptionsHelper.getEffectiveComponentModel(
context.getOptions(),
componentModel

View File

@ -71,7 +71,7 @@ import org.mapstruct.ap.prism.DecoratedWithPrism;
import org.mapstruct.ap.prism.MapperPrism;
import org.mapstruct.ap.util.Executables;
import org.mapstruct.ap.util.Filters;
import org.mapstruct.ap.util.MapperSettings;
import org.mapstruct.ap.util.MapperConfig;
import org.mapstruct.ap.util.Strings;
/**
@ -152,7 +152,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
* @return The effective policy for reporting unmapped getReturnType properties.
*/
private ReportingPolicy getEffectiveUnmappedTargetPolicy(TypeElement element) {
MapperSettings mapperSettings = MapperSettings.getInstanceOn( element );
MapperConfig mapperSettings = MapperConfig.getInstanceOn( element );
boolean setViaAnnotation = mapperSettings.isSetUnmappedTargetPolicy();
ReportingPolicy annotationValue = ReportingPolicy.valueOf( mapperSettings.unmappedTargetPolicy() );
@ -244,7 +244,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
List<MapperReference> mapperReferences = new LinkedList<MapperReference>();
List<String> variableNames = new LinkedList<String>();
MapperSettings mapperPrism = MapperSettings.getInstanceOn( element );
MapperConfig mapperPrism = MapperConfig.getInstanceOn( element );
for ( TypeMirror usedMapper : mapperPrism.uses() ) {
DefaultMapperReference mapperReference = DefaultMapperReference.getInstance(

View File

@ -48,7 +48,7 @@ import org.mapstruct.ap.prism.MapMappingPrism;
import org.mapstruct.ap.prism.MappingPrism;
import org.mapstruct.ap.prism.MappingsPrism;
import org.mapstruct.ap.util.AnnotationProcessingException;
import org.mapstruct.ap.util.MapperSettings;
import org.mapstruct.ap.util.MapperConfig;
/**
* A {@link ModelElementProcessor} which retrieves a list of {@link SourceMethod}s
@ -99,7 +99,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
//Add all methods of used mappers in order to reference them in the aggregated model
if ( mapperRequiresImplementation ) {
MapperSettings mapperSettings = MapperSettings.getInstanceOn( element );
MapperConfig mapperSettings = MapperConfig.getInstanceOn( element );
if ( !mapperSettings.isValid() ) {
throw new AnnotationProcessingException(
"Couldn't retrieve @Mapper annotation", element, mapperSettings.getAnnotationMirror()

View File

@ -32,25 +32,32 @@ import org.mapstruct.ap.prism.MapperConfigPrism;
import org.mapstruct.ap.prism.MapperPrism;
/**
* Class decorating the {@link MapperPrism} with the 'default' configuration.
*
* If no configuration for a property is defined in the {@link org.mapstruct.Mapper} annotation this
* decorator will revert to the {@link org.mapstruct.Mapper#config() } defined mapper.
*
* {@link org.mapstruct.MapperConfig#uses() } will add its Mappers to the ones defined in
* {@link org.mapstruct.Mapper#uses() }
*
* @author Sjaak Derksen
*/
public class MapperSettings {
public class MapperConfig {
private final MapperPrism mapperPrism;
private final MapperConfigPrism mapperConfigPrism;
public static MapperSettings getInstanceOn(Element e) {
return new MapperSettings( MapperPrism.getInstanceOn( e ) );
public static MapperConfig getInstanceOn(Element e) {
return new MapperConfig( MapperPrism.getInstanceOn( e ) );
}
public static MapperSettings getInstance(AnnotationMirror mirror ) {
return new MapperSettings( MapperPrism.getInstance( mirror ) );
public static MapperConfig getInstance(AnnotationMirror mirror ) {
return new MapperConfig( MapperPrism.getInstance( mirror ) );
}
private MapperSettings( MapperPrism mapperPrism ) {
private MapperConfig( MapperPrism mapperPrism ) {
this.mapperPrism = mapperPrism;
TypeMirror typeMirror = mapperPrism.mapperConfig();
TypeMirror typeMirror = mapperPrism.config();
if ( typeMirror.getKind().equals( TypeKind.DECLARED ) ) {
this.mapperConfigPrism = MapperConfigPrism.getInstanceOn( ( (DeclaredType) typeMirror ).asElement() );
}

View File

@ -25,7 +25,7 @@ import org.mapstruct.factory.Mappers;
*
* @author Sjaak Derksen
*/
@Mapper(uses = { CustomMapperViaMapper.class }, mapperConfig = CentralConfig.class )
@Mapper(uses = { CustomMapperViaMapper.class }, config = CentralConfig.class )
public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );

View File

@ -25,7 +25,7 @@ import org.mapstruct.factory.Mappers;
*
* @author Sjaak Derksen
*/
@Mapper(uses = { CustomMapperViaMapper.class }, mapperConfig = CentralConfig.class )
@Mapper(uses = { CustomMapperViaMapper.class }, config = CentralConfig.class )
public interface SourceTargetMapperError {
SourceTargetMapperError INSTANCE = Mappers.getMapper( SourceTargetMapperError.class );

View File

@ -27,7 +27,7 @@ import org.mapstruct.factory.Mappers;
* @author Sjaak Derksen
*/
@Mapper(uses = { CustomMapperViaMapper.class },
mapperConfig = CentralConfig.class,
config = CentralConfig.class,
unmappedTargetPolicy = ReportingPolicy.WARN
)
public interface SourceTargetMapperWarn {