Class LifecycleOverloadDeduplicateSelector

java.lang.Object
org.mapstruct.ap.internal.model.source.selector.LifecycleOverloadDeduplicateSelector

public class LifecycleOverloadDeduplicateSelector extends Object
Selector for deduplicating overloaded lifecycle callback methods whose parameter signatures differ only by type hierarchy.

In the context of lifecycle callback method selection (such as @BeforeMapping or @AfterMapping), it is possible to have multiple overloaded methods whose parameter lists are structurally identical except for the specific types, where those types are related by inheritance (e.g., one parameter is a superclass or subclass of another).

This selector groups such methods by their effective parameter signature (ignoring differences only in type hierarchy), and, within each group, retains only the method whose parameter types have the closest inheritance distance to the actual invocation types. This ensures that, for each group of nearly identical overloads, only the most specific and appropriate method is selected.

Example (see Issue3849Test):


 @AfterMapping
 default void afterMapping(Parent source, @MappingTarget ParentDto target) { ... }
 @AfterMapping
 default void afterMapping(Parent source, @MappingTarget ChildDto target) { ... }
 
When mapping a Child to a ChildDto, only the method with ChildDto is selected, even though both methods match by signature except for the target type's inheritance relationship.