use of org.mapstruct.ap.internal.model.source.selector.SelectedMethod 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.source.selector.SelectedMethod in project mapstruct by mapstruct.
the class PresenceCheckMethodResolver method findMatchingPresenceCheckMethod.
private static SelectedMethod<SourceMethod> findMatchingPresenceCheckMethod(Method method, SelectionParameters selectionParameters, MappingBuilderContext ctx) {
MethodSelectors selectors = new MethodSelectors(ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager());
Type booleanType = ctx.getTypeFactory().getType(Boolean.class);
List<SelectedMethod<SourceMethod>> matchingMethods = selectors.getMatchingMethods(method, getAllAvailableMethods(method, ctx.getSourceModel()), Collections.emptyList(), booleanType, booleanType, SelectionCriteria.forPresenceCheckMethods(selectionParameters));
if (matchingMethods.isEmpty()) {
return null;
}
if (matchingMethods.size() > 1) {
ctx.getMessager().printMessage(method.getExecutable(), Message.GENERAL_AMBIGUOUS_PRESENCE_CHECK_METHOD, selectionParameters.getSourceRHS().getSourceType().describe(), matchingMethods.stream().map(SelectedMethod::getMethod).map(Method::describe).collect(Collectors.joining(", ")));
return null;
}
return matchingMethods.get(0);
}
use of org.mapstruct.ap.internal.model.source.selector.SelectedMethod in project mapstruct by mapstruct.
the class LifecycleCallbackFactory method collectLifecycleCallbackMethods.
private static List<LifecycleCallbackMethodReference> collectLifecycleCallbackMethods(Method method, SelectionParameters selectionParameters, List<SourceMethod> callbackMethods, MappingBuilderContext ctx, Set<String> existingVariableNames) {
MethodSelectors selectors = new MethodSelectors(ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory());
List<SelectedMethod<SourceMethod>> matchingMethods = selectors.getMatchingMethods(method, callbackMethods, Collections.<Type>emptyList(), method.getResultType(), SelectionCriteria.forLifecycleMethods(selectionParameters));
return toLifecycleCallbackMethodRefs(method, matchingMethods, ctx, existingVariableNames);
}
use of org.mapstruct.ap.internal.model.source.selector.SelectedMethod in project mapstruct by mapstruct.
the class LifecycleMethodResolver method collectLifecycleCallbackMethods.
private static List<LifecycleCallbackMethodReference> collectLifecycleCallbackMethods(Method method, Type targetType, SelectionParameters selectionParameters, List<SourceMethod> callbackMethods, MappingBuilderContext ctx, Set<String> existingVariableNames) {
MethodSelectors selectors = new MethodSelectors(ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager());
List<SelectedMethod<SourceMethod>> matchingMethods = selectors.getMatchingMethods(method, callbackMethods, Collections.emptyList(), targetType, method.getReturnType(), SelectionCriteria.forLifecycleMethods(selectionParameters));
return toLifecycleCallbackMethodRefs(method, matchingMethods, ctx, existingVariableNames);
}
Aggregations