Search in sources :

Example 1 with SupportingConstructorFragment

use of org.mapstruct.ap.internal.model.SupportingConstructorFragment in project mapstruct by mapstruct.

the class MapperCreationProcessor method getMapper.

private Mapper getMapper(TypeElement element, MapperOptions mapperOptions, List<SourceMethod> methods) {
    List<MappingMethod> mappingMethods = getMappingMethods(mapperOptions, methods);
    mappingMethods.addAll(mappingContext.getUsedSupportedMappings());
    mappingMethods.addAll(mappingContext.getMappingsToGenerate());
    // handle fields
    List<Field> fields = new ArrayList<>(mappingContext.getMapperReferences());
    Set<Field> supportingFieldSet = new LinkedHashSet<>(mappingContext.getUsedSupportedFields());
    addAllFieldsIn(mappingContext.getUsedSupportedMappings(), supportingFieldSet);
    fields.addAll(supportingFieldSet);
    // handle constructorfragments
    Set<SupportingConstructorFragment> constructorFragments = new LinkedHashSet<>();
    addAllFragmentsIn(mappingContext.getUsedSupportedMappings(), constructorFragments);
    Mapper mapper = new Mapper.Builder().element(element).methods(mappingMethods).fields(fields).constructorFragments(constructorFragments).options(options).versionInformation(versionInformation).decorator(getDecorator(element, methods, mapperOptions)).typeFactory(typeFactory).elementUtils(elementUtils).extraImports(getExtraImports(element, mapperOptions)).implName(mapperOptions.implementationName()).implPackage(mapperOptions.implementationPackage()).suppressGeneratorTimestamp(mapperOptions.suppressTimestampInGenerated()).build();
    if (!mappingContext.getForgedMethodsUnderCreation().isEmpty()) {
        messager.printMessage(element, Message.GENERAL_NOT_ALL_FORGED_CREATED, mappingContext.getForgedMethodsUnderCreation().keySet());
    }
    if (element.getModifiers().contains(Modifier.PRIVATE)) {
        // If the mapper element is private then we should report an error
        // we can't generate an implementation for a private mapper
        mappingContext.getMessager().printMessage(element, Message.GENERAL_CANNOT_IMPLEMENT_PRIVATE_MAPPER, element.getSimpleName().toString(), element.getKind() == ElementKind.INTERFACE ? "interface" : "class");
    }
    return mapper;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Field(org.mapstruct.ap.internal.model.Field) Mapper(org.mapstruct.ap.internal.model.Mapper) ContainerMappingMethodBuilder(org.mapstruct.ap.internal.model.ContainerMappingMethodBuilder) MapMappingMethod(org.mapstruct.ap.internal.model.MapMappingMethod) IterableMappingMethod(org.mapstruct.ap.internal.model.IterableMappingMethod) ValueMappingMethod(org.mapstruct.ap.internal.model.ValueMappingMethod) MappingMethod(org.mapstruct.ap.internal.model.MappingMethod) StreamMappingMethod(org.mapstruct.ap.internal.model.StreamMappingMethod) ContainerMappingMethod(org.mapstruct.ap.internal.model.ContainerMappingMethod) BeanMappingMethod(org.mapstruct.ap.internal.model.BeanMappingMethod) ArrayList(java.util.ArrayList) SupportingConstructorFragment(org.mapstruct.ap.internal.model.SupportingConstructorFragment)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 BeanMappingMethod (org.mapstruct.ap.internal.model.BeanMappingMethod)1 ContainerMappingMethod (org.mapstruct.ap.internal.model.ContainerMappingMethod)1 ContainerMappingMethodBuilder (org.mapstruct.ap.internal.model.ContainerMappingMethodBuilder)1 Field (org.mapstruct.ap.internal.model.Field)1 IterableMappingMethod (org.mapstruct.ap.internal.model.IterableMappingMethod)1 MapMappingMethod (org.mapstruct.ap.internal.model.MapMappingMethod)1 Mapper (org.mapstruct.ap.internal.model.Mapper)1 MappingMethod (org.mapstruct.ap.internal.model.MappingMethod)1 StreamMappingMethod (org.mapstruct.ap.internal.model.StreamMappingMethod)1 SupportingConstructorFragment (org.mapstruct.ap.internal.model.SupportingConstructorFragment)1 ValueMappingMethod (org.mapstruct.ap.internal.model.ValueMappingMethod)1