Class AnnotationBasedComponentModelProcessor
- java.lang.Object
-
- org.mapstruct.ap.internal.processor.AnnotationBasedComponentModelProcessor
-
- All Implemented Interfaces:
ModelElementProcessor<Mapper,Mapper>
- Direct Known Subclasses:
CdiComponentProcessor,JakartaCdiComponentProcessor,JakartaComponentProcessor,Jsr330ComponentProcessor,SpringComponentProcessor
public abstract class AnnotationBasedComponentModelProcessor extends java.lang.Object implements ModelElementProcessor<Mapper,Mapper>
AnModelElementProcessorwhich converts the givenMapperobject into an annotation based component model in case a matching model is selected as target component model for this 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 TypeFactorytypeFactory
-
Constructor Summary
Constructors Constructor Description AnnotationBasedComponentModelProcessor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleanadditionalPublicEmptyConstructor()protected voidadjustDecorator(Mapper mapper, InjectionStrategyGem injectionStrategy)private AnnotatedConstructorbuildAnnotatedConstructorForDecorator(Decorator decorator)private AnnotatedConstructorbuildAnnotatedConstructorForMapper(Mapper mapper)private voidbuildConstructors(Mapper mapper)protected abstract java.lang.StringgetComponentModelIdentifier()protected java.util.List<Annotation>getDecoratorAnnotations()protected java.util.List<Annotation>getDelegatorReferenceAnnotations(Mapper mapper)protected abstract java.util.List<Annotation>getMapperReferenceAnnotations()intgetPriority()Returns the priority value of this processor which must be between 1 (highest priority) and 10000 (lowest priority).protected abstract java.util.List<Annotation>getTypeAnnotations(Mapper mapper)protected TypeFactorygetTypeFactory()Mapperprocess(ModelElementProcessor.ProcessorContext context, javax.lang.model.element.TypeElement mapperTypeElement, Mapper mapper)Processes the given source element, representing a Java bean mapper in one form or another.private voidremoveDuplicateAnnotations(java.util.List<AnnotationMapperReference> annotationMapperReferences, java.util.List<Annotation> mapperReferenceAnnotations)Removes duplicate constructor parameter annotations.protected FieldreplacementMapperReference(Field originalReference, java.util.List<Annotation> annotations, InjectionStrategyGem injectionStrategy)protected abstract booleanrequiresGenerationOfDecoratorClass()private java.util.List<MapperReference>toMapperReferences(java.util.List<Field> fields)
-
-
-
Field Detail
-
typeFactory
private TypeFactory typeFactory
-
-
Method Detail
-
process
public Mapper process(ModelElementProcessor.ProcessorContext context, javax.lang.model.element.TypeElement mapperTypeElement, Mapper mapper)
Description copied from interface:ModelElementProcessorProcesses the given source element, representing a Java bean mapper in one form or another.- Specified by:
processin interfaceModelElementProcessor<Mapper,Mapper>- Parameters:
context- Context providing common infrastructure objects.mapperTypeElement- The original type element from which the given mapper object is derived.mapper- 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.
-
adjustDecorator
protected void adjustDecorator(Mapper mapper, InjectionStrategyGem injectionStrategy)
-
toMapperReferences
private java.util.List<MapperReference> toMapperReferences(java.util.List<Field> fields)
-
buildConstructors
private void buildConstructors(Mapper mapper)
-
buildAnnotatedConstructorForMapper
private AnnotatedConstructor buildAnnotatedConstructorForMapper(Mapper mapper)
-
buildAnnotatedConstructorForDecorator
private AnnotatedConstructor buildAnnotatedConstructorForDecorator(Decorator decorator)
-
removeDuplicateAnnotations
private void removeDuplicateAnnotations(java.util.List<AnnotationMapperReference> annotationMapperReferences, java.util.List<Annotation> mapperReferenceAnnotations)
Removes duplicate constructor parameter annotations. If an annotation is already present on the constructor, it does not have be defined on the constructor parameter, too. For example, for CDI, the javax.inject.Inject annotation is on the constructor and does not need to be on the constructor parameters.- Parameters:
annotationMapperReferences- annotations to annotate the constructor parameter withmapperReferenceAnnotations- annotations to annotate the constructor with
-
additionalPublicEmptyConstructor
protected boolean additionalPublicEmptyConstructor()
-
getDelegatorReferenceAnnotations
protected java.util.List<Annotation> getDelegatorReferenceAnnotations(Mapper mapper)
-
replacementMapperReference
protected Field replacementMapperReference(Field originalReference, java.util.List<Annotation> annotations, InjectionStrategyGem injectionStrategy)
- Parameters:
originalReference- the reference to be replacedannotations- the list of annotationsinjectionStrategy- strategy for injection- Returns:
- the mapper reference replacing the original one
-
getComponentModelIdentifier
protected abstract java.lang.String getComponentModelIdentifier()
- Returns:
- the component model identifier
-
getTypeAnnotations
protected abstract java.util.List<Annotation> getTypeAnnotations(Mapper mapper)
- Parameters:
mapper- the mapper- Returns:
- the annotation(s) to be added at the mapper type implementation
-
getDecoratorAnnotations
protected java.util.List<Annotation> getDecoratorAnnotations()
- Returns:
- the annotation(s) to be added at the decorator of the mapper
-
getMapperReferenceAnnotations
protected abstract java.util.List<Annotation> getMapperReferenceAnnotations()
- Returns:
- the annotation of the field for the mapper reference
-
requiresGenerationOfDecoratorClass
protected abstract boolean requiresGenerationOfDecoratorClass()
- Returns:
- if a decorator (sub-)class needs to be generated or not
-
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<Mapper,Mapper>- Returns:
- The priority value of this processor.
-
getTypeFactory
protected TypeFactory getTypeFactory()
-
-