Search in sources :

Example 1 with InjectionStrategyGem

use of org.mapstruct.ap.internal.gem.InjectionStrategyGem in project mapstruct by mapstruct.

the class AnnotationBasedComponentModelProcessor method process.

@Override
public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, Mapper mapper) {
    this.typeFactory = context.getTypeFactory();
    MapperOptions mapperAnnotation = MapperOptions.getInstanceOn(mapperTypeElement, context.getOptions());
    String componentModel = mapperAnnotation.componentModel();
    InjectionStrategyGem injectionStrategy = mapperAnnotation.getInjectionStrategy();
    if (!getComponentModelIdentifier().equalsIgnoreCase(componentModel)) {
        return mapper;
    }
    for (Annotation typeAnnotation : getTypeAnnotations(mapper)) {
        mapper.addAnnotation(typeAnnotation);
    }
    if (!requiresGenerationOfDecoratorClass()) {
        mapper.removeDecorator();
    } else if (mapper.getDecorator() != null) {
        adjustDecorator(mapper, injectionStrategy);
    }
    List<Annotation> annotations = getMapperReferenceAnnotations();
    ListIterator<Field> iterator = mapper.getFields().listIterator();
    while (iterator.hasNext()) {
        Field reference = iterator.next();
        if (reference instanceof MapperReference) {
            iterator.remove();
            iterator.add(replacementMapperReference(reference, annotations, injectionStrategy));
        }
    }
    if (injectionStrategy == InjectionStrategyGem.CONSTRUCTOR) {
        buildConstructors(mapper);
    }
    return mapper;
}
Also used : MapperOptions(org.mapstruct.ap.internal.model.source.MapperOptions) Field(org.mapstruct.ap.internal.model.Field) MapperReference(org.mapstruct.ap.internal.model.MapperReference) AnnotationMapperReference(org.mapstruct.ap.internal.model.AnnotationMapperReference) InjectionStrategyGem(org.mapstruct.ap.internal.gem.InjectionStrategyGem) Annotation(org.mapstruct.ap.internal.model.Annotation)

Aggregations

InjectionStrategyGem (org.mapstruct.ap.internal.gem.InjectionStrategyGem)1 Annotation (org.mapstruct.ap.internal.model.Annotation)1 AnnotationMapperReference (org.mapstruct.ap.internal.model.AnnotationMapperReference)1 Field (org.mapstruct.ap.internal.model.Field)1 MapperReference (org.mapstruct.ap.internal.model.MapperReference)1 MapperOptions (org.mapstruct.ap.internal.model.source.MapperOptions)1