private static List<SourceMethod> filterCandidatesByQualifiers( Method method, SelectionParameters selectionParameters, List<SourceMethod> candidates, MappingBuilderContext ctx) { QualifierSelector selector = new QualifierSelector(ctx.getTypeUtils(), ctx.getElementUtils()); return selector.getMatchingMethods( method, candidates, null, null, new SelectionCriteria(selectionParameters, null, false, false)); }
/** * @param method the method to obtain the afterMapping methods for * @param selectionParameters method selectionParameters * @param ctx the builder context * @param existingVariableNames list of already used variable names * @return all applicable {@code @AfterMapping} methods for the given method */ public static List<LifecycleCallbackMethodReference> afterMappingMethods( Method method, SelectionParameters selectionParameters, MappingBuilderContext ctx, Set<String> existingVariableNames) { return collectLifecycleCallbackMethods( method, selectionParameters, filterAfterMappingMethods(ctx.getSourceModel()), ctx, existingVariableNames); }
private static List<Parameter> getAvailableParameters(Method method, MappingBuilderContext ctx) { List<Parameter> availableParams = new ArrayList<Parameter>(method.getParameters()); if (method.getMappingTargetParameter() == null) { availableParams.add(new Parameter(null, method.getResultType(), true, false, false)); } Parameter targetTypeParameter = new Parameter( null, ctx.getTypeFactory().classTypeOf(method.getResultType()), false, true, false); availableParams.add(targetTypeParameter); return availableParams; }
private static List<LifecycleCallbackMethodReference> toLifecycleCallbackMethodRefs( Method method, List<SourceMethod> candidates, Map<SourceMethod, List<Parameter>> parameterAssignmentsForSourceMethod, MappingBuilderContext ctx, Set<String> existingVariableNames) { List<LifecycleCallbackMethodReference> result = new ArrayList<LifecycleCallbackMethodReference>(); for (SourceMethod candidate : candidates) { markMapperReferenceAsUsed(ctx.getMapperReferences(), candidate); result.add( new LifecycleCallbackMethodReference( candidate, parameterAssignmentsForSourceMethod.get(candidate), method.getReturnType(), method.getResultType(), existingVariableNames)); } return result; }
public IterableMappingMethod build() { Type sourceParameterType = first(method.getSourceParameters()).getType(); Type resultType = method.getResultType(); Type sourceElementType = sourceParameterType.isArrayType() ? sourceParameterType.getComponentType() : first(sourceParameterType.getTypeParameters()).getTypeBound(); Type targetElementType = resultType.isArrayType() ? resultType.getComponentType() : first(resultType.getTypeParameters()).getTypeBound(); String loopVariableName = Strings.getSaveVariableName(sourceElementType.getName(), method.getParameterNames()); Assignment assignment = ctx.getMappingResolver() .getTargetAssignment( method, "collection element", sourceElementType, targetElementType, null, // there is no targetPropertyName formattingParameters, selectionParameters, loopVariableName, false); if (assignment == null) { if (method instanceof ForgedMethod) { // leave messaging to calling property mapping return null; } else { ctx.getMessager() .printMessage(method.getExecutable(), Message.ITERABLEMAPPING_MAPPING_NOT_FOUND); } } else { if (method instanceof ForgedMethod) { ForgedMethod forgedMethod = (ForgedMethod) method; forgedMethod.addThrownTypes(assignment.getThrownTypes()); } } // target accessor is setter, so decorate assignment as setter if (resultType.isArrayType()) { assignment = new LocalVarWrapper(assignment, method.getThrownTypes()); } else { assignment = new SetterWrapper(assignment, method.getThrownTypes()); } // mapNullToDefault boolean mapNullToDefault = false; if (method.getMapperConfiguration() != null) { mapNullToDefault = method.getMapperConfiguration().isMapToDefault(nullValueMappingStrategy); } MethodReference factoryMethod = null; if (!method.isUpdateMethod()) { factoryMethod = ctx.getMappingResolver().getFactoryMethod(method, method.getResultType(), null); } List<LifecycleCallbackMethodReference> beforeMappingMethods = LifecycleCallbackFactory.beforeMappingMethods(method, selectionParameters, ctx); List<LifecycleCallbackMethodReference> afterMappingMethods = LifecycleCallbackFactory.afterMappingMethods(method, selectionParameters, ctx); return new IterableMappingMethod( method, assignment, factoryMethod, mapNullToDefault, loopVariableName, beforeMappingMethods, afterMappingMethods); }