Class TypeSelector
- java.lang.Object
-
- org.mapstruct.ap.internal.model.source.selector.TypeSelector
-
- All Implemented Interfaces:
MethodSelector
public class TypeSelector extends java.lang.Object implements MethodSelector
Selects those methods from the given input set which match the given source and target types (viaMethodMatcher).
-
-
Field Summary
Fields Modifier and Type Field Description private FormattingMessagermessagerprivate TypeFactorytypeFactory
-
Constructor Summary
Constructors Constructor Description TypeSelector(TypeFactory typeFactory, FormattingMessager messager)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddMappingTargetAndTargetTypeBindings(java.util.List<ParameterBinding> availableParams, Type targetType)Adds default parameter bindings for the mapping-target and target-type if not already available.private static java.util.List<Type>extractTypes(java.util.List<ParameterBinding> parameters)private static java.util.List<ParameterBinding>findCandidateBindingsForParameter(java.util.List<ParameterBinding> candidateParameters, Parameter parameter)private java.util.List<ParameterBinding>getAvailableParameterBindingsFromMethod(Method method, Type targetType, SourceRHS sourceRHS)private java.util.List<ParameterBinding>getAvailableParameterBindingsFromSourceTypes(java.util.List<Type> sourceTypes, Type targetType, Method mappingMethod)private static java.util.List<java.util.List<ParameterBinding>>getCandidateParameterBindingPermutations(java.util.List<ParameterBinding> availableParams, java.util.List<Parameter> methodParameters)<T extends Method>
java.util.List<SelectedMethod<T>>getMatchingMethods(Method mappingMethod, java.util.List<SelectedMethod<T>> methods, java.util.List<Type> sourceTypes, Type mappingTargetType, Type returnType, SelectionCriteria criteria)Selects those methods which match the given types and other criteriaprivate <T extends Method>
SelectedMethod<T>getMatchingParameterBinding(Type returnType, Method mappingMethod, SelectedMethod<T> selectedMethodInfo, java.util.List<java.util.List<ParameterBinding>> parameterAssignmentVariants)private booleanparameterBindingNotMatchesParameterVariableNames(java.util.List<ParameterBinding> parameterBindings, java.util.List<Parameter> parameters)Checks if the given parameter-bindings have the same variable name than the given parameters.
The first entry in the parameter-bindings belongs to the first entry in the parameters and so on.
-
-
-
Field Detail
-
typeFactory
private TypeFactory typeFactory
-
messager
private FormattingMessager messager
-
-
Constructor Detail
-
TypeSelector
public TypeSelector(TypeFactory typeFactory, FormattingMessager messager)
-
-
Method Detail
-
getMatchingMethods
public <T extends Method> java.util.List<SelectedMethod<T>> getMatchingMethods(Method mappingMethod, java.util.List<SelectedMethod<T>> methods, java.util.List<Type> sourceTypes, Type mappingTargetType, Type returnType, SelectionCriteria criteria)
Description copied from interface:MethodSelectorSelects those methods which match the given types and other criteria- Specified by:
getMatchingMethodsin interfaceMethodSelector- Type Parameters:
T- either SourceMethod or BuiltInMethod- Parameters:
mappingMethod- mapping method, defined in Mapper for which this selection is carried outmethods- list of available methodssourceTypes- parameter type(s) that should be matchedmappingTargetType- mappingTargetType that should be matchedreturnType- return type that should be matchedcriteria- criteria used in the selection process- Returns:
- list of methods that passes the matching process
-
getAvailableParameterBindingsFromMethod
private java.util.List<ParameterBinding> getAvailableParameterBindingsFromMethod(Method method, Type targetType, SourceRHS sourceRHS)
-
getAvailableParameterBindingsFromSourceTypes
private java.util.List<ParameterBinding> getAvailableParameterBindingsFromSourceTypes(java.util.List<Type> sourceTypes, Type targetType, Method mappingMethod)
-
addMappingTargetAndTargetTypeBindings
private void addMappingTargetAndTargetTypeBindings(java.util.List<ParameterBinding> availableParams, Type targetType)
Adds default parameter bindings for the mapping-target and target-type if not already available.- Parameters:
availableParams- Already available params, new entries will be added to this listtargetType- Target type
-
getMatchingParameterBinding
private <T extends Method> SelectedMethod<T> getMatchingParameterBinding(Type returnType, Method mappingMethod, SelectedMethod<T> selectedMethodInfo, java.util.List<java.util.List<ParameterBinding>> parameterAssignmentVariants)
-
parameterBindingNotMatchesParameterVariableNames
private boolean parameterBindingNotMatchesParameterVariableNames(java.util.List<ParameterBinding> parameterBindings, java.util.List<Parameter> parameters)
Checks if the given parameter-bindings have the same variable name than the given parameters.
The first entry in the parameter-bindings belongs to the first entry in the parameters and so on.- Parameters:
parameterBindings- List of parameter bindingsparameters- List of parameters, must have the same size than theparameterBindingslist- Returns:
trueas soon as there is a parameter with a different variable name than the binding
-
getCandidateParameterBindingPermutations
private static java.util.List<java.util.List<ParameterBinding>> getCandidateParameterBindingPermutations(java.util.List<ParameterBinding> availableParams, java.util.List<Parameter> methodParameters)
- Parameters:
availableParams- parameter bindings available in the scope of the method callmethodParameters- parameters of the method that is inspected- Returns:
- all parameter binding permutations for which proper type checks need to be conducted.
-
findCandidateBindingsForParameter
private static java.util.List<ParameterBinding> findCandidateBindingsForParameter(java.util.List<ParameterBinding> candidateParameters, Parameter parameter)
- Parameters:
candidateParameters- available for assignment.parameter- that need assignment from one of the candidate parameter bindings.- Returns:
- list of candidate parameter bindings that might be assignable.
-
extractTypes
private static java.util.List<Type> extractTypes(java.util.List<ParameterBinding> parameters)
-
-