use of org.mapstruct.ap.internal.model.source.ParameterProvidedMethods in project mapstruct by mapstruct.
the class MethodRetrievalProcessor method retrieveLifecycleMethodsFromContext.
private ParameterProvidedMethods retrieveLifecycleMethodsFromContext(List<Parameter> contextParameters, TypeElement mapperToImplement, MapperConfiguration mapperConfig) {
ParameterProvidedMethods.Builder builder = ParameterProvidedMethods.builder();
for (Parameter contextParam : contextParameters) {
if (contextParam.getType().isPrimitive()) {
continue;
}
List<SourceMethod> contextParamMethods = retrieveMethods(contextParam.getType().getTypeElement(), mapperToImplement, mapperConfig, Collections.<SourceMethod>emptyList());
List<SourceMethod> lifecycleMethods = new ArrayList<SourceMethod>(contextParamMethods.size());
for (SourceMethod sourceMethod : contextParamMethods) {
if (sourceMethod.isLifecycleCallbackMethod()) {
lifecycleMethods.add(sourceMethod);
}
}
builder.addMethodsForParameter(contextParam, lifecycleMethods);
}
return builder.build();
}
use of org.mapstruct.ap.internal.model.source.ParameterProvidedMethods in project mapstruct by mapstruct.
the class ObjectFactoryMethodResolver 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 @ObjectFactory annotation
if (methodProvidedByParams.hasObjectFactoryAnnotation()) {
availableMethods.add(methodProvidedByParams);
}
}
availableMethods.addAll(sourceModelMethods);
return availableMethods;
}
use of org.mapstruct.ap.internal.model.source.ParameterProvidedMethods in project mapstruct by mapstruct.
the class MethodRetrievalProcessor method getMethodRequiringImplementation.
private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, ExecutableElement method, List<Parameter> parameters, boolean containsTargetTypeParameter, MapperOptions mapperOptions, List<SourceMethod> prototypeMethods, TypeElement mapperToImplement) {
Type returnType = typeFactory.getReturnType(methodType);
List<Type> exceptionTypes = typeFactory.getThrownTypes(methodType);
List<Parameter> sourceParameters = Parameter.getSourceParameters(parameters);
List<Parameter> contextParameters = Parameter.getContextParameters(parameters);
Parameter targetParameter = extractTargetParameter(parameters);
Type resultType = selectResultType(returnType, targetParameter);
boolean isValid = checkParameterAndReturnType(method, sourceParameters, targetParameter, contextParameters, resultType, returnType, containsTargetTypeParameter);
if (!isValid) {
return null;
}
ParameterProvidedMethods contextProvidedMethods = retrieveContextProvidedMethods(contextParameters, mapperToImplement, mapperOptions);
BeanMappingOptions beanMappingOptions = BeanMappingOptions.getInstanceOn(BeanMappingGem.instanceOn(method), mapperOptions, method, messager, typeUtils, typeFactory);
RepeatableMappings repeatableMappings = new RepeatableMappings();
Set<MappingOptions> mappingOptions = repeatableMappings.getMappings(method, beanMappingOptions);
IterableMappingOptions iterableMappingOptions = IterableMappingOptions.fromGem(IterableMappingGem.instanceOn(method), mapperOptions, method, messager, typeUtils);
MapMappingOptions mapMappingOptions = MapMappingOptions.fromGem(MapMappingGem.instanceOn(method), mapperOptions, method, messager, typeUtils);
EnumMappingOptions enumMappingOptions = EnumMappingOptions.getInstanceOn(method, mapperOptions, enumTransformationStrategies, messager);
// We want to get as much error reporting as possible.
// If targetParameter is not null it means we have an update method
SubclassValidator subclassValidator = new SubclassValidator(messager, typeUtils);
Set<SubclassMappingOptions> subclassMappingOptions = getSubclassMappings(sourceParameters, targetParameter != null ? null : resultType, method, beanMappingOptions, subclassValidator);
return new SourceMethod.Builder().setExecutable(method).setParameters(parameters).setReturnType(returnType).setExceptionTypes(exceptionTypes).setMapper(mapperOptions).setBeanMappingOptions(beanMappingOptions).setMappingOptions(mappingOptions).setIterableMappingOptions(iterableMappingOptions).setMapMappingOptions(mapMappingOptions).setValueMappingOptionss(getValueMappings(method)).setEnumMappingOptions(enumMappingOptions).setSubclassMappings(subclassMappingOptions).setSubclassValidator(subclassValidator).setTypeUtils(typeUtils).setTypeFactory(typeFactory).setPrototypeMethods(prototypeMethods).setContextProvidedMethods(contextProvidedMethods).setVerboseLogging(options.isVerbose()).build();
}
use of org.mapstruct.ap.internal.model.source.ParameterProvidedMethods in project mapstruct by mapstruct.
the class LifecycleCallbackFactory 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<SourceMethod>(methodsProvidedByParams.size() + sourceModelMethods.size());
availableMethods.addAll(methodsProvidedByParams);
availableMethods.addAll(sourceModelMethods);
return availableMethods;
}
use of org.mapstruct.ap.internal.model.source.ParameterProvidedMethods in project mapstruct by mapstruct.
the class MethodRetrievalProcessor method getMethodRequiringImplementation.
private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, ExecutableElement method, List<Parameter> parameters, boolean containsTargetTypeParameter, MapperConfiguration mapperConfig, List<SourceMethod> prototypeMethods, TypeElement mapperToImplement) {
Type returnType = typeFactory.getReturnType(methodType);
List<Type> exceptionTypes = typeFactory.getThrownTypes(methodType);
List<Parameter> sourceParameters = Parameter.getSourceParameters(parameters);
List<Parameter> contextParameters = Parameter.getContextParameters(parameters);
Parameter targetParameter = extractTargetParameter(parameters);
Type resultType = selectResultType(returnType, targetParameter);
boolean isValid = checkParameterAndReturnType(method, sourceParameters, targetParameter, contextParameters, resultType, returnType, containsTargetTypeParameter);
if (!isValid) {
return null;
}
ParameterProvidedMethods contextProvidedMethods = retrieveLifecycleMethodsFromContext(contextParameters, mapperToImplement, mapperConfig);
return new SourceMethod.Builder().setExecutable(method).setParameters(parameters).setReturnType(returnType).setExceptionTypes(exceptionTypes).setMappings(getMappings(method)).setIterableMapping(IterableMapping.fromPrism(IterableMappingPrism.getInstanceOn(method), method, messager, typeUtils)).setMapMapping(MapMapping.fromPrism(MapMappingPrism.getInstanceOn(method), method, messager, typeUtils)).setBeanMapping(BeanMapping.fromPrism(BeanMappingPrism.getInstanceOn(method), method, messager, typeUtils)).setValueMappings(getValueMappings(method)).setTypeUtils(typeUtils).setMessager(messager).setTypeFactory(typeFactory).setMapperConfiguration(mapperConfig).setPrototypeMethods(prototypeMethods).setContextProvidedMethods(contextProvidedMethods).build();
}
Aggregations