Class MappingProcessor

  • All Implemented Interfaces:
    Processor

    @SupportedAnnotationTypes("org.mapstruct.Mapper")
    @SupportedOptions({"mapstruct.suppressGeneratorTimestamp","mapstruct.suppressGeneratorVersionInfoComment","mapstruct.unmappedTargetPolicy","mapstruct.unmappedSourcePolicy","mapstruct.defaultComponentModel","mapstruct.defaultInjectionStrategy","mapstruct.disableBuilders","mapstruct.verbose","mapstruct.nullValueIterableMappingStrategy","mapstruct.nullValueMapMappingStrategy"})
    public class MappingProcessor
    extends AbstractProcessor
    A JSR 269 annotation Processor which generates the implementations for mapper interfaces (interfaces annotated with @Mapper).

    Implementation notes:

    The generation happens by incrementally building up a model representation of each mapper to be generated (a Mapper object), which is then written into the resulting Java source file.

    The model instantiation and processing happens in several phases/passes by applying a sequence of ModelElementProcessors. The processors to apply are retrieved using the Java service loader mechanism and are processed in order of their priority. The general processing flow is this:

    • retrieve mapping methods
    • create the Mapper model
    • perform enrichments and modifications (e.g. add annotations for dependency injection)
    • if no error occurred, write out the model into Java source files

    For reading annotation attributes, gems as generated with help of Gem Tools. These gems allow comfortable access to annotations and their attributes without depending on their class objects.

    The creation of Java source files is done using the FreeMarker template engine. Each node of the mapper model has a corresponding FreeMarker template file which provides the Java representation of that element and can include sub-elements via a custom FreeMarker directive. That way writing out a root node of the model (Mapper) will recursively include all contained sub-elements (such as its methods, their property mappings etc.).

    Author:
    Gunnar Morling