use of org.mapstruct.ap.internal.model.common.FormattingParameters in project mapstruct by mapstruct.
the class IterableMappingOptions method fromGem.
public static IterableMappingOptions fromGem(IterableMappingGem iterableMapping, MapperOptions mapperOptions, ExecutableElement method, FormattingMessager messager, TypeUtils typeUtils) {
if (iterableMapping == null || !isConsistent(iterableMapping, method, messager)) {
IterableMappingOptions options = new IterableMappingOptions(null, null, null, mapperOptions);
return options;
}
SelectionParameters selection = new SelectionParameters(iterableMapping.qualifiedBy().get(), iterableMapping.qualifiedByName().get(), iterableMapping.elementTargetType().getValue(), typeUtils);
FormattingParameters formatting = new FormattingParameters(iterableMapping.dateFormat().get(), iterableMapping.numberFormat().get(), iterableMapping.mirror(), iterableMapping.dateFormat().getAnnotationValue(), method);
IterableMappingOptions options = new IterableMappingOptions(formatting, selection, iterableMapping, mapperOptions);
return options;
}
use of org.mapstruct.ap.internal.model.common.FormattingParameters in project mapstruct by mapstruct.
the class MappingOptions method addInstance.
public static void addInstance(MappingGem mapping, ExecutableElement method, BeanMappingOptions beanMappingOptions, FormattingMessager messager, TypeUtils typeUtils, Set<MappingOptions> mappings) {
if (!isConsistent(mapping, method, messager)) {
return;
}
String source = mapping.source().getValue();
String constant = mapping.constant().getValue();
String expression = getExpression(mapping, method, messager);
String defaultExpression = getDefaultExpression(mapping, method, messager);
String conditionExpression = getConditionExpression(mapping, method, messager);
String dateFormat = mapping.dateFormat().getValue();
String numberFormat = mapping.numberFormat().getValue();
String defaultValue = mapping.defaultValue().getValue();
Set<String> dependsOn = mapping.dependsOn().hasValue() ? new LinkedHashSet(mapping.dependsOn().getValue()) : Collections.emptySet();
FormattingParameters formattingParam = new FormattingParameters(dateFormat, numberFormat, mapping.mirror(), mapping.dateFormat().getAnnotationValue(), method);
SelectionParameters selectionParams = new SelectionParameters(mapping.qualifiedBy().get(), mapping.qualifiedByName().get(), mapping.conditionQualifiedBy().get(), mapping.conditionQualifiedByName().get(), mapping.resultType().getValue(), typeUtils);
MappingOptions options = new MappingOptions(mapping.target().getValue(), method, mapping.target().getAnnotationValue(), source, mapping.source().getAnnotationValue(), constant, expression, defaultExpression, conditionExpression, defaultValue, mapping.ignore().get(), formattingParam, selectionParams, dependsOn, mapping, null, beanMappingOptions);
if (mappings.contains(options)) {
messager.printMessage(method, Message.PROPERTYMAPPING_DUPLICATE_TARGETS, mapping.target().get());
} else {
mappings.add(options);
}
}
use of org.mapstruct.ap.internal.model.common.FormattingParameters in project mapstruct by mapstruct.
the class MapMappingOptions method fromGem.
public static MapMappingOptions fromGem(MapMappingGem mapMapping, MapperOptions mapperOptions, ExecutableElement method, FormattingMessager messager, TypeUtils typeUtils) {
if (mapMapping == null || !isConsistent(mapMapping, method, messager)) {
MapMappingOptions options = new MapMappingOptions(null, null, null, null, null, mapperOptions);
return options;
}
SelectionParameters keySelection = new SelectionParameters(mapMapping.keyQualifiedBy().get(), mapMapping.keyQualifiedByName().get(), mapMapping.keyTargetType().getValue(), typeUtils);
SelectionParameters valueSelection = new SelectionParameters(mapMapping.valueQualifiedBy().get(), mapMapping.valueQualifiedByName().get(), mapMapping.valueTargetType().getValue(), typeUtils);
FormattingParameters keyFormatting = new FormattingParameters(mapMapping.keyDateFormat().get(), mapMapping.keyNumberFormat().get(), mapMapping.mirror(), mapMapping.keyDateFormat().getAnnotationValue(), method);
FormattingParameters valueFormatting = new FormattingParameters(mapMapping.valueDateFormat().get(), mapMapping.valueNumberFormat().get(), mapMapping.mirror(), mapMapping.valueDateFormat().getAnnotationValue(), method);
MapMappingOptions options = new MapMappingOptions(keyFormatting, keySelection, valueFormatting, valueSelection, mapMapping, mapperOptions);
return options;
}
use of org.mapstruct.ap.internal.model.common.FormattingParameters in project mapstruct by mapstruct.
the class MapperCreationProcessor method getMappingMethods.
private List<MappingMethod> getMappingMethods(MapperOptions mapperAnnotation, List<SourceMethod> methods) {
List<MappingMethod> mappingMethods = new ArrayList<>();
for (SourceMethod method : methods) {
if (!method.overridesMethod()) {
continue;
}
mergeInheritedOptions(method, mapperAnnotation, methods, new ArrayList<>(), null);
MappingMethodOptions mappingOptions = method.getOptions();
boolean hasFactoryMethod = false;
if (method.isIterableMapping()) {
this.messager.note(1, Message.ITERABLEMAPPING_CREATE_NOTE, method);
IterableMappingMethod iterableMappingMethod = createWithElementMappingMethod(method, mappingOptions, new IterableMappingMethod.Builder());
hasFactoryMethod = iterableMappingMethod.getFactoryMethod() != null;
mappingMethods.add(iterableMappingMethod);
} else if (method.isMapMapping()) {
MapMappingMethod.Builder builder = new MapMappingMethod.Builder();
SelectionParameters keySelectionParameters = null;
FormattingParameters keyFormattingParameters = null;
SelectionParameters valueSelectionParameters = null;
FormattingParameters valueFormattingParameters = null;
NullValueMappingStrategyGem nullValueMappingStrategy = null;
if (mappingOptions.getMapMapping() != null) {
keySelectionParameters = mappingOptions.getMapMapping().getKeySelectionParameters();
keyFormattingParameters = mappingOptions.getMapMapping().getKeyFormattingParameters();
valueSelectionParameters = mappingOptions.getMapMapping().getValueSelectionParameters();
valueFormattingParameters = mappingOptions.getMapMapping().getValueFormattingParameters();
nullValueMappingStrategy = mappingOptions.getMapMapping().getNullValueMappingStrategy();
}
this.messager.note(1, Message.MAPMAPPING_CREATE_NOTE, method);
MapMappingMethod mapMappingMethod = builder.mappingContext(mappingContext).method(method).keyFormattingParameters(keyFormattingParameters).keySelectionParameters(keySelectionParameters).valueFormattingParameters(valueFormattingParameters).valueSelectionParameters(valueSelectionParameters).build();
hasFactoryMethod = mapMappingMethod.getFactoryMethod() != null;
mappingMethods.add(mapMappingMethod);
} else if (method.isValueMapping()) {
// prefer value mappings over enum mapping
this.messager.note(1, Message.VALUEMAPPING_CREATE_NOTE, method);
ValueMappingMethod valueMappingMethod = new ValueMappingMethod.Builder().mappingContext(mappingContext).method(method).valueMappings(mappingOptions.getValueMappings()).enumMapping(mappingOptions.getEnumMappingOptions()).build();
if (valueMappingMethod != null) {
mappingMethods.add(valueMappingMethod);
}
} else if (method.isRemovedEnumMapping()) {
messager.printMessage(method.getExecutable(), Message.ENUMMAPPING_REMOVED);
} else if (method.isStreamMapping()) {
this.messager.note(1, Message.STREAMMAPPING_CREATE_NOTE, method);
StreamMappingMethod streamMappingMethod = createWithElementMappingMethod(method, mappingOptions, new StreamMappingMethod.Builder());
// If we do StreamMapping that means that internally there is a way to generate the result type
hasFactoryMethod = streamMappingMethod.getFactoryMethod() != null || method.getResultType().isStreamType();
mappingMethods.add(streamMappingMethod);
} else {
this.messager.note(1, Message.BEANMAPPING_CREATE_NOTE, method);
BuilderGem builder = method.getOptions().getBeanMapping().getBuilder();
Type userDefinedReturnType = getUserDesiredReturnType(method);
Type builderBaseType = userDefinedReturnType != null ? userDefinedReturnType : method.getReturnType();
BeanMappingMethod.Builder beanMappingBuilder = new BeanMappingMethod.Builder();
BeanMappingMethod beanMappingMethod = beanMappingBuilder.mappingContext(mappingContext).sourceMethod(method).userDefinedReturnType(userDefinedReturnType).returnTypeBuilder(typeFactory.builderTypeFor(builderBaseType, builder)).build();
// We can consider that the bean mapping method can always be constructed. If there is a problem
// it would have been reported in its build
hasFactoryMethod = true;
if (beanMappingMethod != null) {
mappingMethods.add(beanMappingMethod);
}
}
if (!hasFactoryMethod) {
// A factory method is allowed to return an interface type and hence, the generated
// implementation as well. The check below must only be executed if there's no factory
// method that could be responsible.
reportErrorIfNoImplementationTypeIsRegisteredForInterfaceReturnType(method);
}
}
return mappingMethods;
}
use of org.mapstruct.ap.internal.model.common.FormattingParameters in project mapstruct by mapstruct.
the class MapperCreationProcessor method createWithElementMappingMethod.
private <M extends ContainerMappingMethod> M createWithElementMappingMethod(SourceMethod method, MappingMethodOptions mappingMethodOptions, ContainerMappingMethodBuilder<?, M> builder) {
FormattingParameters formattingParameters = null;
SelectionParameters selectionParameters = null;
if (mappingMethodOptions.getIterableMapping() != null) {
formattingParameters = mappingMethodOptions.getIterableMapping().getFormattingParameters();
selectionParameters = mappingMethodOptions.getIterableMapping().getSelectionParameters();
}
return builder.mappingContext(mappingContext).method(method).formattingParameters(formattingParameters).selectionParameters(selectionParameters).build();
}
Aggregations