#983, #975 rephrase documentation of AfterMapping/BeforeMapping and document @Context usage

This commit is contained in:
Andreas Gudian 2017-01-02 00:17:25 +01:00
parent ac03999170
commit 32bf03642c
2 changed files with 52 additions and 45 deletions

View File

@ -23,36 +23,40 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.mapstruct.util.Experimental;
/** /**
* Marks a method to be invoked at the end of a generated mapping method, right before the last {@code return} statement * Marks a method to be invoked at the end of a generated mapping method, right before the last {@code return} statement
* of the mapping method. The method can be implemented in an abstract mapper class or be declared in a type (class or * of the mapping method. The method can be implemented in an abstract mapper class, be declared in a type (class or
* interface) referenced in {@link Mapper#uses()} in order to be used in a mapping method. * interface) referenced in {@link Mapper#uses()}, or in a type used as {@code @}{@link Context} parameter in order to
* be used in a mapping method.
* <p> * <p>
* Only methods with return type {@code void} may be annotated with this annotation. * The method invocation is only generated if the return type of the method (if non-{@code void}) is assignable to the
* <p> * return type of the mapping method and all parameters can be <em>assigned</em> by the available source, target or
* If the method has parameters, the method invocation is only generated if all parameters can be <em>assigned</em> by * context parameters of the mapping method:
* the source or target parameters of the mapping method:
* <ul> * <ul>
* <li>A parameter annotated with {@code @}{@link MappingTarget} is populated with the target instance of the mapping. * <li>A parameter annotated with {@code @}{@link MappingTarget} is populated with the target instance of the mapping.
* </li> * </li>
* <li>A parameter annotated with {@code @}{@link TargetType} is populated with the target type of the mapping.</li> * <li>A parameter annotated with {@code @}{@link TargetType} is populated with the target type of the mapping.</li>
* <li>Any other parameter is populated with a source parameter of the mapping, whereas each source parameter is used * <li>Parameters annotated with {@code @}{@link Context} are populated with the context parameters of the mapping
* once at most.</li> * method.</li>
* <li>Any other parameter is populated with a source parameter of the mapping.</li>
* </ul> * </ul>
* <p> * <p>
* All <em>after-mapping</em> methods that can be applied to a mapping method will be used. Their order is determined by * For non-{@code void} methods, the return value of the method invocation is returned as the result of the mapping
* their location of definition: * method if it is not {@code null}.
* <ul> * <p>
* <li>The order of methods within one type can not be guaranteed, as it depends on the compiler and the processing * All <em>after-mapping</em> methods that can be applied to a mapping method will be used. {@code @}{@link Qualifier} /
* environment implementation.</li> * {@code @}{@link Named} can be used to filter the methods to use.
* <li>Methods declared in one type are used after methods declared in their super-type.</li> * <p>
* <li>Methods implemented in the mapper itself are used before methods from types referenced in {@link Mapper#uses()}. * The order of the method invocation is determined by their location of definition:
* <ol>
* <li>Methods declared on {@code @}{@link Context} parameters, ordered by the parameter order.</li>
* <li>Methods implemented in the mapper itself.</li>
* <li>Methods from types referenced in {@link Mapper#uses()}, in the order of the type declaration in the annotation.
* </li> * </li>
* <li>Types referenced in {@link Mapper#uses()} are searched for <em>after-mapping</em> methods in the order specified * <li>Methods declared in one type are used after methods declared in their super-type</li>
* in the annotation.</li> * </ol>
* </ul> * <em>Important:</em> the order of methods declared within one type can not be guaranteed, as it depends on the
* compiler and the processing environment implementation.
* <p> * <p>
* Example: * Example:
* *
@ -97,8 +101,8 @@ import org.mapstruct.util.Experimental;
* *
* @author Andreas Gudian * @author Andreas Gudian
* @see BeforeMapping * @see BeforeMapping
* @see Context
*/ */
@Experimental
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS) @Retention(RetentionPolicy.CLASS)
public @interface AfterMapping { public @interface AfterMapping {

View File

@ -23,39 +23,42 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.mapstruct.util.Experimental;
/** /**
* Marks a method to be invoked at the beginning of a generated mapping method. The method can be implemented in an * Marks a method to be invoked at the beginning of a generated mapping method. The method can be implemented in an
* abstract mapper class or be declared in a type (class or interface) referenced in {@link Mapper#uses()} in order to * abstract mapper class, be declared in a type (class or interface) referenced in {@link Mapper#uses()}, or in a type
* be used in a mapping method. * used as {@code @}{@link Context} parameter in order to be used in a mapping method.
* <p> * <p>
* Only methods with return type {@code void} may be annotated with this annotation. * The method invocation is only generated if the return type of the method (if non-{@code void}) is assignable to the
* <p> * return type of the mapping method and all parameters can be <em>assigned</em> by the available source, target or
* If the method has parameters, the method invocation is only generated if all parameters can be <em>assigned</em> by * context parameters of the mapping method:
* the source or target parameters of the mapping method:
* <ul> * <ul>
* <li>A parameter annotated with {@code @}{@link MappingTarget} is populated with the target instance of the mapping. * <li>A parameter annotated with {@code @}{@link MappingTarget} is populated with the target instance of the mapping.
* </li> * </li>
* <li>A parameter annotated with {@code @}{@link TargetType} is populated with the target type of the mapping.</li> * <li>A parameter annotated with {@code @}{@link TargetType} is populated with the target type of the mapping.</li>
* <li>Any other parameter is populated with a source parameter of the mapping, whereas each source parameter is used * <li>Parameters annotated with {@code @}{@link Context} are populated with the context parameters of the mapping
* once at most.</li> * method.</li>
* <li>Any other parameter is populated with a source parameter of the mapping.</li>
* </ul> * </ul>
* If a <em>before-mapping</em> method does not contain a {@code @}{@link MappingTarget} parameter, it is invoked
* directly at the beginning of the applicable mapping method. If it contains a {@code @}{@link MappingTarget}
* parameter, the method is invoked after the target parameter has been initialized in the mapping method.
* <p> * <p>
* All <em>before-mapping</em> methods that can be applied to a mapping method will be used. Their order is determined * For non-{@code void} methods, the return value of the method invocation is returned as the result of the mapping
* by their location of definition: * method if it is not {@code null}.
* <ul> * <p>
* <li>The order of methods within one type can not be guaranteed, as it depends on the compiler and the processing * All <em>before-mapping</em> methods that can be applied to a mapping method will be used. {@code @}{@link Qualifier}
* environment implementation.</li> * / {@code @}{@link Named} can be used to filter the methods to use.
* <li>Methods declared in one type are used after methods declared in their super-type.</li> * <p>
* <li>Methods implemented in the mapper itself are used before methods from types referenced in {@link Mapper#uses()}. * The order of the method invocation is determined by their their variant and their location of definition:
* <ol>
* <li>Methods without an {@code @}{@link MappingTarget} parameter are called before any null-checks on source
* parameters and constructing a new target bean.</li>
* <li>Methods with an {@code @}{@link MappingTarget} parameter are called after constructing a new target bean.</li>
* <li>Methods declared on {@code @}{@link Context} parameters, ordered by the parameter order.</li>
* <li>Methods implemented in the mapper itself.</li>
* <li>Methods from types referenced in {@link Mapper#uses()}, in the order of the type declaration in the annotation.
* </li> * </li>
* <li>Types referenced in {@link Mapper#uses()} are searched for <em>after-mapping</em> methods in the order specified * <li>Methods declared in one type are used after methods declared in their super-type</li>
* in the annotation.</li> * </ol>
* </ul> * <em>Important:</em> the order of methods declared within one type can not be guaranteed, as it depends on the
* compiler and the processing environment implementation.
* <p> * <p>
* Example: * Example:
* *
@ -101,8 +104,8 @@ import org.mapstruct.util.Experimental;
* *
* @author Andreas Gudian * @author Andreas Gudian
* @see AfterMapping * @see AfterMapping
* @see Context
*/ */
@Experimental
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS) @Retention(RetentionPolicy.CLASS)
public @interface BeforeMapping { public @interface BeforeMapping {