Search in sources :

Example 1 with MapperConfiguration

use of org.mapstruct.ap.internal.util.MapperConfiguration in project mapstruct by mapstruct.

the class AnnotationBasedComponentModelProcessor method process.

@Override
public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, Mapper mapper) {
    this.typeFactory = context.getTypeFactory();
    MapperConfiguration mapperConfiguration = MapperConfiguration.getInstanceOn(mapperTypeElement);
    String componentModel = mapperConfiguration.componentModel(context.getOptions());
    InjectionStrategyPrism injectionStrategy = mapperConfiguration.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<MapperReference> iterator = mapper.getReferencedMappers().listIterator();
    while (iterator.hasNext()) {
        MapperReference reference = iterator.next();
        iterator.remove();
        iterator.add(replacementMapperReference(reference, annotations, injectionStrategy));
    }
    if (injectionStrategy == InjectionStrategyPrism.CONSTRUCTOR) {
        buildConstructors(mapper);
    }
    return mapper;
}
Also used : InjectionStrategyPrism(org.mapstruct.ap.internal.prism.InjectionStrategyPrism) MapperReference(org.mapstruct.ap.internal.model.MapperReference) AnnotationMapperReference(org.mapstruct.ap.internal.model.AnnotationMapperReference) MapperConfiguration(org.mapstruct.ap.internal.util.MapperConfiguration) Annotation(org.mapstruct.ap.internal.model.Annotation)

Example 2 with MapperConfiguration

use of org.mapstruct.ap.internal.util.MapperConfiguration 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 = context.getMessager();
    this.options = context.getOptions();
    this.versionInformation = context.getVersionInformation();
    this.typeFactory = context.getTypeFactory();
    MapperConfiguration mapperConfig = MapperConfiguration.getInstanceOn(mapperTypeElement);
    List<MapperReference> mapperReferences = initReferencedMappers(mapperTypeElement, mapperConfig);
    MappingBuilderContext ctx = new MappingBuilderContext(typeFactory, elementUtils, typeUtils, messager, options, new MappingResolverImpl(messager, elementUtils, typeUtils, typeFactory, new ArrayList<Method>(sourceModel), mapperReferences), mapperTypeElement, // Consider removing those methods directly into MappingBuilderContext.
    Collections.unmodifiableList(sourceModel), mapperReferences);
    this.mappingContext = ctx;
    return getMapper(mapperTypeElement, mapperConfig, sourceModel);
}
Also used : 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) MapperConfiguration(org.mapstruct.ap.internal.util.MapperConfiguration)

Example 3 with MapperConfiguration

use of org.mapstruct.ap.internal.util.MapperConfiguration in project mapstruct by mapstruct.

the class MapperCreationProcessor method getExtraImports.

private SortedSet<Type> getExtraImports(TypeElement element) {
    SortedSet<Type> extraImports = new TreeSet<Type>();
    MapperConfiguration mapperConfiguration = MapperConfiguration.getInstanceOn(element);
    for (TypeMirror extraImport : mapperConfiguration.imports()) {
        Type type = typeFactory.getType(extraImport);
        extraImports.add(type);
    }
    // Add original package if a dest package has been set
    if (!"default".equals(mapperConfiguration.implementationPackage())) {
        extraImports.add(typeFactory.getType(element));
    }
    return extraImports;
}
Also used : Type(org.mapstruct.ap.internal.model.common.Type) TypeMirror(javax.lang.model.type.TypeMirror) TreeSet(java.util.TreeSet) MapperConfiguration(org.mapstruct.ap.internal.util.MapperConfiguration)

Example 4 with MapperConfiguration

use of org.mapstruct.ap.internal.util.MapperConfiguration 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.typeUtils = context.getTypeUtils();
    this.elementUtils = context.getElementUtils();
    MapperConfiguration mapperConfig = MapperConfiguration.getInstanceOn(mapperTypeElement);
    if (!mapperConfig.isValid()) {
        throw new AnnotationProcessingException("Couldn't retrieve @Mapper annotation", mapperTypeElement, mapperConfig.getAnnotationMirror());
    }
    List<SourceMethod> prototypeMethods = retrievePrototypeMethods(mapperTypeElement, mapperConfig);
    return retrieveMethods(mapperTypeElement, mapperTypeElement, mapperConfig, prototypeMethods);
}
Also used : MapperConfiguration(org.mapstruct.ap.internal.util.MapperConfiguration) AnnotationProcessingException(org.mapstruct.ap.internal.util.AnnotationProcessingException) SourceMethod(org.mapstruct.ap.internal.model.source.SourceMethod)

Aggregations

MapperConfiguration (org.mapstruct.ap.internal.util.MapperConfiguration)4 MapperReference (org.mapstruct.ap.internal.model.MapperReference)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 TypeMirror (javax.lang.model.type.TypeMirror)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 MappingBuilderContext (org.mapstruct.ap.internal.model.MappingBuilderContext)1 Type (org.mapstruct.ap.internal.model.common.Type)1 SourceMethod (org.mapstruct.ap.internal.model.source.SourceMethod)1 InjectionStrategyPrism (org.mapstruct.ap.internal.prism.InjectionStrategyPrism)1 MappingResolverImpl (org.mapstruct.ap.internal.processor.creation.MappingResolverImpl)1 AnnotationProcessingException (org.mapstruct.ap.internal.util.AnnotationProcessingException)1