Search in sources :

Example 6 with MapperReference

use of org.mapstruct.ap.internal.model.MapperReference in project mapstruct by mapstruct.

the class AnnotationBasedComponentModelProcessor method buildAnnotatedConstructorForMapper.

private AnnotatedConstructor buildAnnotatedConstructorForMapper(Mapper mapper) {
    List<MapperReference> mapperReferences = toMapperReferences(mapper.getFields());
    List<AnnotationMapperReference> mapperReferencesForConstructor = new ArrayList<>(mapperReferences.size());
    for (MapperReference mapperReference : mapperReferences) {
        if (mapperReference.isUsed()) {
            mapperReferencesForConstructor.add((AnnotationMapperReference) mapperReference);
        }
    }
    List<Annotation> mapperReferenceAnnotations = getMapperReferenceAnnotations();
    removeDuplicateAnnotations(mapperReferencesForConstructor, mapperReferenceAnnotations);
    return AnnotatedConstructor.forComponentModels(mapper.getName(), mapperReferencesForConstructor, mapperReferenceAnnotations, mapper.getConstructor(), additionalPublicEmptyConstructor());
}
Also used : AnnotationMapperReference(org.mapstruct.ap.internal.model.AnnotationMapperReference) MapperReference(org.mapstruct.ap.internal.model.MapperReference) AnnotationMapperReference(org.mapstruct.ap.internal.model.AnnotationMapperReference) ArrayList(java.util.ArrayList) Annotation(org.mapstruct.ap.internal.model.Annotation)

Example 7 with MapperReference

use of org.mapstruct.ap.internal.model.MapperReference 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 8 with MapperReference

use of org.mapstruct.ap.internal.model.MapperReference in project mapstruct by mapstruct.

the class MappingResolverImpl method findMapperReference.

private MapperReference findMapperReference(Method method) {
    for (MapperReference ref : mapperReferences) {
        if (ref.getType().equals(method.getDeclaringMapper())) {
            ref.setUsed(ref.isUsed() || !method.isStatic());
            ref.setTypeRequiresImport(true);
            return ref;
        }
    }
    return null;
}
Also used : MapperReference(org.mapstruct.ap.internal.model.MapperReference)

Aggregations

MapperReference (org.mapstruct.ap.internal.model.MapperReference)8 DefaultMapperReference (org.mapstruct.ap.internal.model.DefaultMapperReference)4 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 TypeMirror (javax.lang.model.type.TypeMirror)2 Annotation (org.mapstruct.ap.internal.model.Annotation)2 AnnotationMapperReference (org.mapstruct.ap.internal.model.AnnotationMapperReference)2 MapperOptions (org.mapstruct.ap.internal.model.source.MapperOptions)2 InjectionStrategyGem (org.mapstruct.ap.internal.gem.InjectionStrategyGem)1 BeanMappingMethod (org.mapstruct.ap.internal.model.BeanMappingMethod)1 ContainerMappingMethod (org.mapstruct.ap.internal.model.ContainerMappingMethod)1 ContainerMappingMethodBuilder (org.mapstruct.ap.internal.model.ContainerMappingMethodBuilder)1 EnumMappingMethod (org.mapstruct.ap.internal.model.EnumMappingMethod)1 Field (org.mapstruct.ap.internal.model.Field)1 HelperMethod (org.mapstruct.ap.internal.model.HelperMethod)1 IterableMappingMethod (org.mapstruct.ap.internal.model.IterableMappingMethod)1 MapMappingMethod (org.mapstruct.ap.internal.model.MapMappingMethod)1 Mapper (org.mapstruct.ap.internal.model.Mapper)1 MappingBuilderContext (org.mapstruct.ap.internal.model.MappingBuilderContext)1 MappingMethod (org.mapstruct.ap.internal.model.MappingMethod)1