Search in sources :

Example 1 with MapperOptions

use of org.mapstruct.ap.internal.model.source.MapperOptions 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)

Example 2 with MapperOptions

use of org.mapstruct.ap.internal.model.source.MapperOptions in project mapstruct by mapstruct.

the class MapperCreationProcessor method process.

@Override
public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, List<SourceMethod> sourceModel) {
    this.elementUtils = context.getElementUtils();
    this.typeUtils = context.getTypeUtils();
    this.messager = new MapperAnnotatedFormattingMessenger(context.getMessager(), mapperTypeElement, context.getTypeUtils());
    this.options = context.getOptions();
    this.versionInformation = context.getVersionInformation();
    this.typeFactory = context.getTypeFactory();
    this.accessorNaming = context.getAccessorNaming();
    MapperOptions mapperOptions = MapperOptions.getInstanceOn(mapperTypeElement, context.getOptions());
    List<MapperReference> mapperReferences = initReferencedMappers(mapperTypeElement, mapperOptions);
    MappingBuilderContext ctx = new MappingBuilderContext(typeFactory, elementUtils, typeUtils, messager, accessorNaming, context.getEnumMappingStrategy(), context.getEnumTransformationStrategies(), options, new MappingResolverImpl(messager, elementUtils, typeUtils, typeFactory, new ArrayList<>(sourceModel), mapperReferences, options.isVerbose()), mapperTypeElement, // Consider removing those methods directly into MappingBuilderContext.
    Collections.unmodifiableList(sourceModel), mapperReferences);
    this.mappingContext = ctx;
    return getMapper(mapperTypeElement, mapperOptions, sourceModel);
}
Also used : MapperOptions(org.mapstruct.ap.internal.model.source.MapperOptions) MappingBuilderContext(org.mapstruct.ap.internal.model.MappingBuilderContext) MappingResolverImpl(org.mapstruct.ap.internal.processor.creation.MappingResolverImpl) DefaultMapperReference(org.mapstruct.ap.internal.model.DefaultMapperReference) MapperReference(org.mapstruct.ap.internal.model.MapperReference) ArrayList(java.util.ArrayList)

Example 3 with MapperOptions

use of org.mapstruct.ap.internal.model.source.MapperOptions in project mapstruct by mapstruct.

the class MethodRetrievalProcessor method process.

@Override
public List<SourceMethod> process(ProcessorContext context, TypeElement mapperTypeElement, Void sourceModel) {
    this.messager = context.getMessager();
    this.typeFactory = context.getTypeFactory();
    this.accessorNaming = context.getAccessorNaming();
    this.typeUtils = context.getTypeUtils();
    this.elementUtils = context.getElementUtils();
    this.enumTransformationStrategies = context.getEnumTransformationStrategies();
    this.options = context.getOptions();
    this.messager.note(0, Message.PROCESSING_NOTE, mapperTypeElement);
    MapperOptions mapperOptions = MapperOptions.getInstanceOn(mapperTypeElement, context.getOptions());
    if (mapperOptions.hasMapperConfig()) {
        this.messager.note(0, Message.CONFIG_NOTE, mapperOptions.mapperConfigType().asElement().getSimpleName());
    }
    if (!mapperOptions.isValid()) {
        throw new AnnotationProcessingException("Couldn't retrieve @Mapper annotation", mapperTypeElement, mapperOptions.getAnnotationMirror());
    }
    List<SourceMethod> prototypeMethods = retrievePrototypeMethods(mapperTypeElement, mapperOptions);
    return retrieveMethods(mapperTypeElement, mapperTypeElement, mapperOptions, prototypeMethods);
}
Also used : MapperOptions(org.mapstruct.ap.internal.model.source.MapperOptions) AnnotationProcessingException(org.mapstruct.ap.internal.util.AnnotationProcessingException) SourceMethod(org.mapstruct.ap.internal.model.source.SourceMethod)

Aggregations

MapperOptions (org.mapstruct.ap.internal.model.source.MapperOptions)3 MapperReference (org.mapstruct.ap.internal.model.MapperReference)2 ArrayList (java.util.ArrayList)1 InjectionStrategyGem (org.mapstruct.ap.internal.gem.InjectionStrategyGem)1 Annotation (org.mapstruct.ap.internal.model.Annotation)1 AnnotationMapperReference (org.mapstruct.ap.internal.model.AnnotationMapperReference)1 DefaultMapperReference (org.mapstruct.ap.internal.model.DefaultMapperReference)1 Field (org.mapstruct.ap.internal.model.Field)1 MappingBuilderContext (org.mapstruct.ap.internal.model.MappingBuilderContext)1 SourceMethod (org.mapstruct.ap.internal.model.source.SourceMethod)1 MappingResolverImpl (org.mapstruct.ap.internal.processor.creation.MappingResolverImpl)1 AnnotationProcessingException (org.mapstruct.ap.internal.util.AnnotationProcessingException)1