Search in sources :

Example 1 with SelectedMethod

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());
}
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 2 with SelectedMethod

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);
}
Also used : Type(org.mapstruct.ap.internal.model.common.Type) SelectedMethod(org.mapstruct.ap.internal.model.source.selector.SelectedMethod) SelectedMethod(org.mapstruct.ap.internal.model.source.selector.SelectedMethod) SourceMethod(org.mapstruct.ap.internal.model.source.SourceMethod) Method(org.mapstruct.ap.internal.model.source.Method) MethodSelectors(org.mapstruct.ap.internal.model.source.selector.MethodSelectors)

Example 3 with SelectedMethod

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);
}
Also used : SelectedMethod(org.mapstruct.ap.internal.model.source.selector.SelectedMethod) MethodSelectors(org.mapstruct.ap.internal.model.source.selector.MethodSelectors)

Example 4 with SelectedMethod

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);
}
Also used : SelectedMethod(org.mapstruct.ap.internal.model.source.selector.SelectedMethod) MethodSelectors(org.mapstruct.ap.internal.model.source.selector.MethodSelectors)

Aggregations

SelectedMethod (org.mapstruct.ap.internal.model.source.selector.SelectedMethod)4 MethodSelectors (org.mapstruct.ap.internal.model.source.selector.MethodSelectors)3 Method (org.mapstruct.ap.internal.model.source.Method)2 HelperMethod (org.mapstruct.ap.internal.model.HelperMethod)1 MapperReference (org.mapstruct.ap.internal.model.MapperReference)1 VirtualMappingMethod (org.mapstruct.ap.internal.model.VirtualMappingMethod)1 Type (org.mapstruct.ap.internal.model.common.Type)1 SourceMethod (org.mapstruct.ap.internal.model.source.SourceMethod)1 BuiltInMethod (org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod)1