Class MapperCreationProcessor
- java.lang.Object
-
- org.mapstruct.ap.internal.processor.MapperCreationProcessor
-
- All Implemented Interfaces:
ModelElementProcessor<java.util.List<SourceMethod>,Mapper>
public class MapperCreationProcessor extends java.lang.Object implements ModelElementProcessor<java.util.List<SourceMethod>,Mapper>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.mapstruct.ap.internal.processor.ModelElementProcessor
ModelElementProcessor.ProcessorContext
-
-
Field Summary
Fields Modifier and Type Field Description private AccessorNamingUtilsaccessorNamingprivate ElementUtilselementUtilsprivate MappingBuilderContextmappingContextprivate FormattingMessagermessagerprivate Optionsoptionsprivate static java.util.List<javax.lang.model.element.Modifier>PUBLIC_CONSTANT_MODIFIERSModifiers for public "constant" e.g.private TypeFactorytypeFactoryprivate TypeUtilstypeUtilsprivate VersionInformationversionInformation
-
Constructor Summary
Constructors Constructor Description MapperCreationProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private <M extends ContainerMappingMethod>
McreateWithElementMappingMethod(SourceMethod method, MappingMethodOptions mappingMethodOptions, ContainerMappingMethodBuilder<?,M> builder)private SourceMethodextractInitializedOptions(SourceMethod resultMethod, java.util.List<SourceMethod> rawMethods, MapperOptions mapperConfig, java.util.List<SourceMethod> initializingMethods, javax.lang.model.element.AnnotationMirror annotationMirror)private javax.lang.model.element.AnnotationMirrorgetAnnotationMirror(InheritConfigurationGem inheritConfiguration)private javax.lang.model.element.AnnotationMirrorgetAnnotationMirror(InheritInverseConfigurationGem inverseConfiguration)private DecoratorgetDecorator(javax.lang.model.element.TypeElement element, java.util.List<SourceMethod> methods, MapperOptions mapperOptions)private java.util.SortedSet<Type>getExtraImports(javax.lang.model.element.TypeElement element, MapperOptions mapperOptions)private SourceMethodgetForwardTemplateMethod(java.util.List<SourceMethod> rawMethods, SourceMethod method, java.util.List<SourceMethod> initializingMethods, MapperOptions mapperConfig)Returns the configuring forward method's options in case the given method is annotated with@InheritConfigurationand exactly one such configuring method can unambiguously be selected (as per the source/target type and optionally the name given via@InheritConfiguration).private SourceMethodgetInverseTemplateMethod(java.util.List<SourceMethod> rawMethods, SourceMethod method, java.util.List<SourceMethod> initializingMethods, MapperOptions mapperConfig)Returns the configuring inverse method's options in case the given method is annotated with@InheritInverseConfigurationand exactly one such configuring method can unambiguously be selected (as per the source/target type and optionally the name given via@InheritInverseConfiguration).private MappergetMapper(javax.lang.model.element.TypeElement element, MapperOptions mapperOptions, java.util.List<SourceMethod> methods)private java.util.List<MappingMethod>getMappingMethods(MapperOptions mapperAnnotation, java.util.List<SourceMethod> methods)intgetPriority()Returns the priority value of this processor which must be between 1 (highest priority) and 10000 (lowest priority).private TypegetUserDesiredReturnType(SourceMethod method)private booleanhasSingletonInstance(javax.lang.model.type.TypeMirror mapper)private java.util.List<MapperReference>initReferencedMappers(javax.lang.model.element.TypeElement element, MapperOptions mapperAnnotation)private booleanisPublicConstantOfType(javax.lang.model.element.Element element, java.lang.String fieldName, javax.lang.model.type.TypeMirror fieldType)private voidmergeInheritedOptions(SourceMethod method, MapperOptions mapperConfig, java.util.List<SourceMethod> availableMethods, java.util.List<SourceMethod> initializingMethods, javax.lang.model.element.AnnotationMirror annotationMirror)Mapperprocess(ModelElementProcessor.ProcessorContext context, javax.lang.model.element.TypeElement mapperTypeElement, java.util.List<SourceMethod> sourceModel)Processes the given source element, representing a Java bean mapper in one form or another.private voidreportErrorIfNoImplementationTypeIsRegisteredForInterfaceReturnType(Method method)private voidreportErrorWhenAmbigousMapping(java.util.List<SourceMethod> candidates, SourceMethod method, InheritConfigurationGem gem)private voidreportErrorWhenAmbigousReverseMapping(java.util.List<SourceMethod> candidates, SourceMethod method, InheritInverseConfigurationGem inverseGem)private voidreportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method, InheritConfigurationGem gem)private voidreportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method, InheritInverseConfigurationGem inverseGem)private voidreportErrorWhenSeveralNamesMatch(java.util.List<SourceMethod> candidates, SourceMethod method, InheritConfigurationGem gem)private voidreportErrorWhenSeveralNamesMatch(java.util.List<SourceMethod> candidates, SourceMethod method, InheritInverseConfigurationGem inverseGem)
-
-
-
Field Detail
-
PUBLIC_CONSTANT_MODIFIERS
private static final java.util.List<javax.lang.model.element.Modifier> PUBLIC_CONSTANT_MODIFIERS
Modifiers for public "constant" e.g. "public static final"
-
elementUtils
private ElementUtils elementUtils
-
typeUtils
private TypeUtils typeUtils
-
messager
private FormattingMessager messager
-
options
private Options options
-
versionInformation
private VersionInformation versionInformation
-
typeFactory
private TypeFactory typeFactory
-
accessorNaming
private AccessorNamingUtils accessorNaming
-
mappingContext
private MappingBuilderContext mappingContext
-
-
Method Detail
-
process
public Mapper process(ModelElementProcessor.ProcessorContext context, javax.lang.model.element.TypeElement mapperTypeElement, java.util.List<SourceMethod> sourceModel)
Description copied from interface:ModelElementProcessorProcesses the given source element, representing a Java bean mapper in one form or another.- Specified by:
processin interfaceModelElementProcessor<java.util.List<SourceMethod>,Mapper>- Parameters:
context- Context providing common infrastructure objects.mapperTypeElement- The original type element from which the given mapper object is derived.sourceModel- The current representation of the bean mapper. Nevernull(the very first processor receives the original type element).- Returns:
- The resulting representation of the bean mapper; may be the same
as the source representation, e.g. if a given implementation just
performs some sort of validity check. Implementations must never
return
nullexcept for the very last processor which generates the resulting Java source file.
-
getPriority
public int getPriority()
Description copied from interface:ModelElementProcessorReturns the priority value of this processor which must be between 1 (highest priority) and 10000 (lowest priority). Processors are invoked in order from highest to lowest priority, starting with the mapping method retrieval processor (priority 1) and finishing with the code generation processor (priority 10000). Processors working on the builtMappermodel must have a priority > 1000.- Specified by:
getPriorityin interfaceModelElementProcessor<java.util.List<SourceMethod>,Mapper>- Returns:
- The priority value of this processor.
-
initReferencedMappers
private java.util.List<MapperReference> initReferencedMappers(javax.lang.model.element.TypeElement element, MapperOptions mapperAnnotation)
-
hasSingletonInstance
private boolean hasSingletonInstance(javax.lang.model.type.TypeMirror mapper)
-
isPublicConstantOfType
private boolean isPublicConstantOfType(javax.lang.model.element.Element element, java.lang.String fieldName, javax.lang.model.type.TypeMirror fieldType)- Returns:
- true if the
elementis a "public static final" field (e.g. a constant) namedfieldNameof type "fieldType"
-
getMapper
private Mapper getMapper(javax.lang.model.element.TypeElement element, MapperOptions mapperOptions, java.util.List<SourceMethod> methods)
-
getDecorator
private Decorator getDecorator(javax.lang.model.element.TypeElement element, java.util.List<SourceMethod> methods, MapperOptions mapperOptions)
-
getExtraImports
private java.util.SortedSet<Type> getExtraImports(javax.lang.model.element.TypeElement element, MapperOptions mapperOptions)
-
getMappingMethods
private java.util.List<MappingMethod> getMappingMethods(MapperOptions mapperAnnotation, java.util.List<SourceMethod> methods)
-
getUserDesiredReturnType
private Type getUserDesiredReturnType(SourceMethod method)
-
createWithElementMappingMethod
private <M extends ContainerMappingMethod> M createWithElementMappingMethod(SourceMethod method, MappingMethodOptions mappingMethodOptions, ContainerMappingMethodBuilder<?,M> builder)
-
mergeInheritedOptions
private void mergeInheritedOptions(SourceMethod method, MapperOptions mapperConfig, java.util.List<SourceMethod> availableMethods, java.util.List<SourceMethod> initializingMethods, javax.lang.model.element.AnnotationMirror annotationMirror)
-
reportErrorIfNoImplementationTypeIsRegisteredForInterfaceReturnType
private void reportErrorIfNoImplementationTypeIsRegisteredForInterfaceReturnType(Method method)
-
getInverseTemplateMethod
private SourceMethod getInverseTemplateMethod(java.util.List<SourceMethod> rawMethods, SourceMethod method, java.util.List<SourceMethod> initializingMethods, MapperOptions mapperConfig)
Returns the configuring inverse method's options in case the given method is annotated with@InheritInverseConfigurationand exactly one such configuring method can unambiguously be selected (as per the source/target type and optionally the name given via@InheritInverseConfiguration).
-
getAnnotationMirror
private javax.lang.model.element.AnnotationMirror getAnnotationMirror(InheritInverseConfigurationGem inverseConfiguration)
-
extractInitializedOptions
private SourceMethod extractInitializedOptions(SourceMethod resultMethod, java.util.List<SourceMethod> rawMethods, MapperOptions mapperConfig, java.util.List<SourceMethod> initializingMethods, javax.lang.model.element.AnnotationMirror annotationMirror)
-
getForwardTemplateMethod
private SourceMethod getForwardTemplateMethod(java.util.List<SourceMethod> rawMethods, SourceMethod method, java.util.List<SourceMethod> initializingMethods, MapperOptions mapperConfig)
Returns the configuring forward method's options in case the given method is annotated with@InheritConfigurationand exactly one such configuring method can unambiguously be selected (as per the source/target type and optionally the name given via@InheritConfiguration). The method cannot be marked forward mapping itself (hence 'other'). And neither can it contain an@InheritReverseConfiguration
-
getAnnotationMirror
private javax.lang.model.element.AnnotationMirror getAnnotationMirror(InheritConfigurationGem inheritConfiguration)
-
reportErrorWhenAmbigousReverseMapping
private void reportErrorWhenAmbigousReverseMapping(java.util.List<SourceMethod> candidates, SourceMethod method, InheritInverseConfigurationGem inverseGem)
-
reportErrorWhenSeveralNamesMatch
private void reportErrorWhenSeveralNamesMatch(java.util.List<SourceMethod> candidates, SourceMethod method, InheritInverseConfigurationGem inverseGem)
-
reportErrorWhenNonMatchingName
private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method, InheritInverseConfigurationGem inverseGem)
-
reportErrorWhenAmbigousMapping
private void reportErrorWhenAmbigousMapping(java.util.List<SourceMethod> candidates, SourceMethod method, InheritConfigurationGem gem)
-
reportErrorWhenSeveralNamesMatch
private void reportErrorWhenSeveralNamesMatch(java.util.List<SourceMethod> candidates, SourceMethod method, InheritConfigurationGem gem)
-
reportErrorWhenNonMatchingName
private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method, InheritConfigurationGem gem)
-
-