Class MappingProcessor
- java.lang.Object
-
- javax.annotation.processing.AbstractProcessor
-
- org.mapstruct.ap.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 annotationProcessor
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
ModelElementProcessor
s. The processors to apply are retrieved using the Java service loader mechanism and are processed in order of theirpriority
. 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
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
ALWAYS_GENERATE_SERVICE_FILE
protected static String
DEFAULT_COMPONENT_MODEL
protected static String
DEFAULT_INJECTION_STRATEGY
protected static String
DISABLE_BUILDERS
protected static String
NULL_VALUE_ITERABLE_MAPPING_STRATEGY
protected static String
NULL_VALUE_MAP_MAPPING_STRATEGY
protected static String
SUPPRESS_GENERATOR_TIMESTAMP
protected static String
SUPPRESS_GENERATOR_VERSION_INFO_COMMENT
protected static String
UNMAPPED_SOURCE_POLICY
protected static String
UNMAPPED_TARGET_POLICY
protected static String
VERBOSE
-
Fields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv
-
-
Constructor Summary
Constructors Constructor Description MappingProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>
getSupportedOptions()
SourceVersion
getSupportedSourceVersion()
void
init(ProcessingEnvironment processingEnv)
boolean
process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment)
-
Methods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, getSupportedAnnotationTypes, isInitialized
-
-
-
-
Field Detail
-
SUPPRESS_GENERATOR_TIMESTAMP
protected static final String SUPPRESS_GENERATOR_TIMESTAMP
- See Also:
- Constant Field Values
-
SUPPRESS_GENERATOR_VERSION_INFO_COMMENT
protected static final String SUPPRESS_GENERATOR_VERSION_INFO_COMMENT
- See Also:
- Constant Field Values
-
UNMAPPED_TARGET_POLICY
protected static final String UNMAPPED_TARGET_POLICY
- See Also:
- Constant Field Values
-
UNMAPPED_SOURCE_POLICY
protected static final String UNMAPPED_SOURCE_POLICY
- See Also:
- Constant Field Values
-
DEFAULT_COMPONENT_MODEL
protected static final String DEFAULT_COMPONENT_MODEL
- See Also:
- Constant Field Values
-
DEFAULT_INJECTION_STRATEGY
protected static final String DEFAULT_INJECTION_STRATEGY
- See Also:
- Constant Field Values
-
ALWAYS_GENERATE_SERVICE_FILE
protected static final String ALWAYS_GENERATE_SERVICE_FILE
- See Also:
- Constant Field Values
-
DISABLE_BUILDERS
protected static final String DISABLE_BUILDERS
- See Also:
- Constant Field Values
-
VERBOSE
protected static final String VERBOSE
- See Also:
- Constant Field Values
-
NULL_VALUE_ITERABLE_MAPPING_STRATEGY
protected static final String NULL_VALUE_ITERABLE_MAPPING_STRATEGY
- See Also:
- Constant Field Values
-
NULL_VALUE_MAP_MAPPING_STRATEGY
protected static final String NULL_VALUE_MAP_MAPPING_STRATEGY
- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init(ProcessingEnvironment processingEnv)
- Specified by:
init
in interfaceProcessor
- Overrides:
init
in classAbstractProcessor
-
getSupportedSourceVersion
public SourceVersion getSupportedSourceVersion()
- Specified by:
getSupportedSourceVersion
in interfaceProcessor
- Overrides:
getSupportedSourceVersion
in classAbstractProcessor
-
process
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment)
- Specified by:
process
in interfaceProcessor
- Specified by:
process
in classAbstractProcessor
-
getSupportedOptions
public Set<String> getSupportedOptions()
- Specified by:
getSupportedOptions
in interfaceProcessor
- Overrides:
getSupportedOptions
in classAbstractProcessor
-
-