Search in sources :

Example 1 with MapperReference

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

the class MapperCreationProcessor method getMapper.

private Mapper getMapper(TypeElement element, MapperConfiguration mapperConfig, List<SourceMethod> methods) {
    List<MapperReference> mapperReferences = mappingContext.getMapperReferences();
    List<MappingMethod> mappingMethods = getMappingMethods(mapperConfig, methods);
    mappingMethods.addAll(mappingContext.getUsedVirtualMappings());
    mappingMethods.addAll(mappingContext.getMappingsToGenerate());
    Mapper mapper = new Mapper.Builder().element(element).mappingMethods(mappingMethods).mapperReferences(mapperReferences).options(options).versionInformation(versionInformation).decorator(getDecorator(element, methods, mapperConfig.implementationName(), mapperConfig.implementationPackage())).typeFactory(typeFactory).elementUtils(elementUtils).extraImports(getExtraImports(element)).implName(mapperConfig.implementationName()).implPackage(mapperConfig.implementationPackage()).build();
    if (!mappingContext.getForgedMethodsUnderCreation().isEmpty()) {
        messager.printMessage(element, Message.GENERAL_NOT_ALL_FORGED_CREATED, mappingContext.getForgedMethodsUnderCreation().keySet());
    }
    return mapper;
}
Also used : Mapper(org.mapstruct.ap.internal.model.Mapper) DefaultMapperReference(org.mapstruct.ap.internal.model.DefaultMapperReference) MapperReference(org.mapstruct.ap.internal.model.MapperReference) ContainerMappingMethodBuilder(org.mapstruct.ap.internal.model.ContainerMappingMethodBuilder) MapMappingMethod(org.mapstruct.ap.internal.model.MapMappingMethod) EnumMappingMethod(org.mapstruct.ap.internal.model.EnumMappingMethod) IterableMappingMethod(org.mapstruct.ap.internal.model.IterableMappingMethod) ValueMappingMethod(org.mapstruct.ap.internal.model.ValueMappingMethod) MappingMethod(org.mapstruct.ap.internal.model.MappingMethod) StreamMappingMethod(org.mapstruct.ap.internal.model.StreamMappingMethod) ContainerMappingMethod(org.mapstruct.ap.internal.model.ContainerMappingMethod) BeanMappingMethod(org.mapstruct.ap.internal.model.BeanMappingMethod)

Example 2 with MapperReference

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

the class MappingResolverImpl method getFactoryMethod.

@Override
public MethodReference getFactoryMethod(final Method mappingMethod, Type targetType, SelectionParameters selectionParameters) {
    List<SelectedMethod<Method>> matchingFactoryMethods = methodSelectors.getMatchingMethods(mappingMethod, sourceModel, java.util.Collections.<Type>emptyList(), targetType, SelectionCriteria.forFactoryMethods(selectionParameters));
    if (matchingFactoryMethods.isEmpty()) {
        return null;
    }
    if (matchingFactoryMethods.size() > 1) {
        messager.printMessage(mappingMethod.getExecutable(), Message.GENERAL_AMBIGIOUS_FACTORY_METHOD, targetType, Strings.join(matchingFactoryMethods, ", "));
        return null;
    }
    SelectedMethod<Method> matchingFactoryMethod = first(matchingFactoryMethods);
    MapperReference ref = findMapperReference(matchingFactoryMethod.getMethod());
    return MethodReference.forMapperReference(matchingFactoryMethod.getMethod(), ref, matchingFactoryMethod.getParameterBindings());
}
Also used : SelectedMethod(org.mapstruct.ap.internal.model.source.selector.SelectedMethod) MapperReference(org.mapstruct.ap.internal.model.MapperReference) BuiltInMethod(org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod) Method(org.mapstruct.ap.internal.model.source.Method) HelperMethod(org.mapstruct.ap.internal.model.HelperMethod) VirtualMappingMethod(org.mapstruct.ap.internal.model.VirtualMappingMethod) SelectedMethod(org.mapstruct.ap.internal.model.source.selector.SelectedMethod)

Example 3 with MapperReference

use of org.mapstruct.ap.internal.model.MapperReference 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 4 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<AnnotationMapperReference> mapperReferencesForConstructor = new ArrayList<AnnotationMapperReference>(mapper.getReferencedMappers().size());
    for (MapperReference mapperReference : mapper.getReferencedMappers()) {
        if (mapperReference.isUsed()) {
            mapperReferencesForConstructor.add((AnnotationMapperReference) mapperReference);
        }
    }
    List<Annotation> mapperReferenceAnnotations = getMapperReferenceAnnotations();
    removeDuplicateAnnotations(mapperReferencesForConstructor, mapperReferenceAnnotations);
    return new AnnotatedConstructor(mapper.getName(), mapperReferencesForConstructor, mapperReferenceAnnotations, additionalPublicEmptyConstructor());
}
Also used : AnnotationMapperReference(org.mapstruct.ap.internal.model.AnnotationMapperReference) AnnotatedConstructor(org.mapstruct.ap.internal.model.AnnotatedConstructor) 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 5 with MapperReference

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

the class MapperCreationProcessor method initReferencedMappers.

private List<MapperReference> initReferencedMappers(TypeElement element, MapperConfiguration mapperConfig) {
    List<MapperReference> result = new LinkedList<MapperReference>();
    List<String> variableNames = new LinkedList<String>();
    for (TypeMirror usedMapper : mapperConfig.uses()) {
        DefaultMapperReference mapperReference = DefaultMapperReference.getInstance(typeFactory.getType(usedMapper), MapperPrism.getInstanceOn(typeUtils.asElement(usedMapper)) != null, typeFactory, variableNames);
        result.add(mapperReference);
        variableNames.add(mapperReference.getVariableName());
    }
    return result;
}
Also used : DefaultMapperReference(org.mapstruct.ap.internal.model.DefaultMapperReference) MapperReference(org.mapstruct.ap.internal.model.MapperReference) TypeMirror(javax.lang.model.type.TypeMirror) LinkedList(java.util.LinkedList) DefaultMapperReference(org.mapstruct.ap.internal.model.DefaultMapperReference)

Aggregations

MapperReference (org.mapstruct.ap.internal.model.MapperReference)7 DefaultMapperReference (org.mapstruct.ap.internal.model.DefaultMapperReference)3 ArrayList (java.util.ArrayList)2 Annotation (org.mapstruct.ap.internal.model.Annotation)2 AnnotationMapperReference (org.mapstruct.ap.internal.model.AnnotationMapperReference)2 MapperConfiguration (org.mapstruct.ap.internal.util.MapperConfiguration)2 LinkedList (java.util.LinkedList)1 TypeMirror (javax.lang.model.type.TypeMirror)1 AnnotatedConstructor (org.mapstruct.ap.internal.model.AnnotatedConstructor)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 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 StreamMappingMethod (org.mapstruct.ap.internal.model.StreamMappingMethod)1