Search in sources :

Example 6 with ParameterProvidedMethods

use of org.mapstruct.ap.internal.model.source.ParameterProvidedMethods in project mapstruct by mapstruct.

the class PresenceCheckMethodResolver method getAllAvailableMethods.

private static List<SourceMethod> getAllAvailableMethods(Method method, List<SourceMethod> sourceModelMethods) {
    ParameterProvidedMethods contextProvidedMethods = method.getContextProvidedMethods();
    if (contextProvidedMethods.isEmpty()) {
        return sourceModelMethods;
    }
    List<SourceMethod> methodsProvidedByParams = contextProvidedMethods.getAllProvidedMethodsInParameterOrder(method.getContextParameters());
    List<SourceMethod> availableMethods = new ArrayList<>(methodsProvidedByParams.size() + sourceModelMethods.size());
    for (SourceMethod methodProvidedByParams : methodsProvidedByParams) {
        // add only methods from context that do have the @Condition annotation
        if (methodProvidedByParams.isPresenceCheck()) {
            availableMethods.add(methodProvidedByParams);
        }
    }
    availableMethods.addAll(sourceModelMethods);
    return availableMethods;
}
Also used : ParameterProvidedMethods(org.mapstruct.ap.internal.model.source.ParameterProvidedMethods) ArrayList(java.util.ArrayList) SourceMethod(org.mapstruct.ap.internal.model.source.SourceMethod)

Example 7 with ParameterProvidedMethods

use of org.mapstruct.ap.internal.model.source.ParameterProvidedMethods in project mapstruct by mapstruct.

the class LifecycleMethodResolver method getAllAvailableMethods.

private static List<SourceMethod> getAllAvailableMethods(Method method, List<SourceMethod> sourceModelMethods) {
    ParameterProvidedMethods contextProvidedMethods = method.getContextProvidedMethods();
    if (contextProvidedMethods.isEmpty()) {
        return sourceModelMethods;
    }
    List<SourceMethod> methodsProvidedByParams = contextProvidedMethods.getAllProvidedMethodsInParameterOrder(method.getContextParameters());
    List<SourceMethod> availableMethods = new ArrayList<>(methodsProvidedByParams.size() + sourceModelMethods.size());
    availableMethods.addAll(methodsProvidedByParams);
    availableMethods.addAll(sourceModelMethods);
    return availableMethods;
}
Also used : ParameterProvidedMethods(org.mapstruct.ap.internal.model.source.ParameterProvidedMethods) ArrayList(java.util.ArrayList) SourceMethod(org.mapstruct.ap.internal.model.source.SourceMethod)

Example 8 with ParameterProvidedMethods

use of org.mapstruct.ap.internal.model.source.ParameterProvidedMethods in project mapstruct by mapstruct.

the class MethodRetrievalProcessor method retrieveContextProvidedMethods.

private ParameterProvidedMethods retrieveContextProvidedMethods(List<Parameter> contextParameters, TypeElement mapperToImplement, MapperOptions mapperConfig) {
    ParameterProvidedMethods.Builder builder = ParameterProvidedMethods.builder();
    for (Parameter contextParam : contextParameters) {
        if (contextParam.getType().isPrimitive() || contextParam.getType().isArrayType()) {
            continue;
        }
        List<SourceMethod> contextParamMethods = retrieveMethods(contextParam.getType().getTypeElement(), mapperToImplement, mapperConfig, Collections.emptyList());
        List<SourceMethod> contextProvidedMethods = new ArrayList<>(contextParamMethods.size());
        for (SourceMethod sourceMethod : contextParamMethods) {
            if (sourceMethod.isLifecycleCallbackMethod() || sourceMethod.isObjectFactory() || sourceMethod.isPresenceCheck()) {
                contextProvidedMethods.add(sourceMethod);
            }
        }
        builder.addMethodsForParameter(contextParam, contextProvidedMethods);
    }
    return builder.build();
}
Also used : ParameterProvidedMethods(org.mapstruct.ap.internal.model.source.ParameterProvidedMethods) ArrayList(java.util.ArrayList) Parameter(org.mapstruct.ap.internal.model.common.Parameter) SourceMethod(org.mapstruct.ap.internal.model.source.SourceMethod)

Aggregations

ParameterProvidedMethods (org.mapstruct.ap.internal.model.source.ParameterProvidedMethods)8 SourceMethod (org.mapstruct.ap.internal.model.source.SourceMethod)7 ArrayList (java.util.ArrayList)6 Parameter (org.mapstruct.ap.internal.model.common.Parameter)4 DeclaredType (javax.lang.model.type.DeclaredType)2 ExecutableType (javax.lang.model.type.ExecutableType)2 Type (org.mapstruct.ap.internal.model.common.Type)2 BeanMappingOptions (org.mapstruct.ap.internal.model.source.BeanMappingOptions)1 EnumMappingOptions (org.mapstruct.ap.internal.model.source.EnumMappingOptions)1 IterableMappingOptions (org.mapstruct.ap.internal.model.source.IterableMappingOptions)1 MapMappingOptions (org.mapstruct.ap.internal.model.source.MapMappingOptions)1 MappingOptions (org.mapstruct.ap.internal.model.source.MappingOptions)1 SubclassMappingOptions (org.mapstruct.ap.internal.model.source.SubclassMappingOptions)1 SubclassValidator (org.mapstruct.ap.internal.model.source.SubclassValidator)1 ValueMappingOptions (org.mapstruct.ap.internal.model.source.ValueMappingOptions)1