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;
}
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());
}
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;
}
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());
}
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;
}
Aggregations