Search in sources :

Example 1 with Mapper

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

the class MapperCreationProcessor method getMapper.

private Mapper getMapper(TypeElement element, MapperConfiguration mapperConfig, List<SourceMethod> methods) {
    List<MapperReference> mapperReferences = mappingContext.getMapperReferences();
    List<MappingMethod> mappingMethods = getMappingMethods(mapperConfig, methods);
    mappingMethods.addAll(mappingContext.getUsedVirtualMappings());
    mappingMethods.addAll(mappingContext.getMappingsToGenerate());
    Mapper mapper = new Mapper.Builder().element(element).mappingMethods(mappingMethods).mapperReferences(mapperReferences).options(options).versionInformation(versionInformation).decorator(getDecorator(element, methods, mapperConfig.implementationName(), mapperConfig.implementationPackage())).typeFactory(typeFactory).elementUtils(elementUtils).extraImports(getExtraImports(element)).implName(mapperConfig.implementationName()).implPackage(mapperConfig.implementationPackage()).build();
    if (!mappingContext.getForgedMethodsUnderCreation().isEmpty()) {
        messager.printMessage(element, Message.GENERAL_NOT_ALL_FORGED_CREATED, mappingContext.getForgedMethodsUnderCreation().keySet());
    }
    return mapper;
}
Also used : Mapper(org.mapstruct.ap.internal.model.Mapper) DefaultMapperReference(org.mapstruct.ap.internal.model.DefaultMapperReference) MapperReference(org.mapstruct.ap.internal.model.MapperReference) ContainerMappingMethodBuilder(org.mapstruct.ap.internal.model.ContainerMappingMethodBuilder) MapMappingMethod(org.mapstruct.ap.internal.model.MapMappingMethod) EnumMappingMethod(org.mapstruct.ap.internal.model.EnumMappingMethod) 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)

Example 2 with Mapper

use of org.mapstruct.ap.internal.model.Mapper 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

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