mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#750 Further expanding comment
This commit is contained in:
parent
e039c74c2a
commit
5e88dae8ce
@ -57,11 +57,17 @@ public @interface IterableMapping {
|
|||||||
Class<? extends Annotation>[] qualifiedBy() default { };
|
Class<? extends Annotation>[] qualifiedBy() default { };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See: { @link #qualifiedBy() }. String form of a predefined { @link @Qualifier }. The { @link @Qualifier }
|
* String-based form of qualifiers; When looking for a suitable mapping method to map this iterable mapping method's
|
||||||
* is more verbose, but offers more flexibility in terms of for instance refactoring. At the other hand, there
|
* element type, MapStruct will only consider those methods carrying directly or indirectly (i.e. on the
|
||||||
* is no need to define own annotations.
|
* class-level) a {@link Named} annotation for each of the specified qualifier names.
|
||||||
|
* <p>
|
||||||
|
* Note that annotation-based qualifiers are generally preferable as they allow more easily to find references and
|
||||||
|
* are safe for refactorings, but name-based qualifiers can be a less verbose alternative when requiring a large
|
||||||
|
* number of qualifiers as no custom annotation types are needed.
|
||||||
*
|
*
|
||||||
* @return the qualifiers
|
* @return One or more qualifier name(s)
|
||||||
|
* @see #qualifiedBy()
|
||||||
|
* @see Named
|
||||||
*/
|
*/
|
||||||
String[] qualifiedByName() default { };
|
String[] qualifiedByName() default { };
|
||||||
|
|
||||||
|
@ -66,11 +66,17 @@ public @interface MapMapping {
|
|||||||
Class<? extends Annotation>[] keyQualifiedBy() default { };
|
Class<? extends Annotation>[] keyQualifiedBy() default { };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See: { @link #keyQualifiedBy() }. String form of a predefined { @link @Qualifier }. The { @link @Qualifier }
|
* String-based form of qualifiers; When looking for a suitable mapping method to map this map mapping method's key
|
||||||
* is more verbose, but offers more flexibility in terms of for instance refactoring. At the other hand, there
|
* type, MapStruct will only consider those methods carrying directly or indirectly (i.e. on the class-level) a
|
||||||
* is no need to define own annotations.
|
* {@link Named} annotation for each of the specified qualifier names.
|
||||||
|
* <p>
|
||||||
|
* Note that annotation-based qualifiers are generally preferable as they allow more easily to find references and
|
||||||
|
* are safe for refactorings, but name-based qualifiers can be a less verbose alternative when requiring a large
|
||||||
|
* number of qualifiers as no custom annotation types are needed.
|
||||||
*
|
*
|
||||||
* @return the qualifiers
|
* @return One or more qualifier name(s)
|
||||||
|
* @see #keyQualifiedBy()
|
||||||
|
* @see Named
|
||||||
*/
|
*/
|
||||||
String[] keyQualifiedByName() default { };
|
String[] keyQualifiedByName() default { };
|
||||||
|
|
||||||
@ -87,11 +93,17 @@ public @interface MapMapping {
|
|||||||
Class<? extends Annotation>[] valueQualifiedBy() default { };
|
Class<? extends Annotation>[] valueQualifiedBy() default { };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See: { @link #valueQualifiedBy() }. String form of a predefined { @link @Qualifier }. The { @link @Qualifier }
|
* String-based form of qualifiers; When looking for a suitable mapping method to map this map mapping method's value
|
||||||
* is more verbose, but offers more flexibility in terms of for instance refactoring. At the other hand, there
|
* type, MapStruct will only consider those methods carrying directly or indirectly (i.e. on the class-level) a
|
||||||
* is no need to define own annotations.
|
* {@link Named} annotation for each of the specified qualifier names.
|
||||||
|
* <p>
|
||||||
|
* Note that annotation-based qualifiers are generally preferable as they allow more easily to find references and
|
||||||
|
* are safe for refactorings, but name-based qualifiers can be a less verbose alternative when requiring a large
|
||||||
|
* number of qualifiers as no custom annotation types are needed.
|
||||||
*
|
*
|
||||||
* @return the qualifiers
|
* @return One or more qualifier name(s)
|
||||||
|
* @see #valueQualifiedBy()
|
||||||
|
* @see Named
|
||||||
*/
|
*/
|
||||||
String[] valueQualifiedByName() default { };
|
String[] valueQualifiedByName() default { };
|
||||||
|
|
||||||
|
@ -24,19 +24,14 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String-based qualifier.
|
* Marks mapping methods with the given qualifier name. Can be used to qualify a single method or all methods of a given
|
||||||
*
|
* type by specifying this annotation on the type level.
|
||||||
* <p>
|
* <p>
|
||||||
* For more info see:
|
* Will be used to to select the correct mapping methods when mapping a bean property type, element of an iterable type
|
||||||
* <ul>
|
* or the key/value of a map type.
|
||||||
* <li>{@link Mapping#qualifiedByName() }</li>
|
|
||||||
* <li>{@link IterableMapping#qualifiedByName() }</li>
|
|
||||||
* <li>{@link MapMapping#keyQualifiedByName() }</li>
|
|
||||||
* <li>{@link MapMapping#valueQualifiedByName() }</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* <p>
|
* <p>
|
||||||
* Example:
|
* Example (both methods of {@code Titles} are capable to convert a string, but the ambiguity is resolved by applying
|
||||||
|
* the qualifiers in {@code @Mapping}:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* <code>
|
* <code>
|
||||||
@ -61,36 +56,46 @@ import java.lang.annotation.Target;
|
|||||||
* GermanRelease toGerman( OriginalRelease movies );
|
* GermanRelease toGerman( OriginalRelease movies );
|
||||||
*
|
*
|
||||||
* }
|
* }
|
||||||
*
|
|
||||||
* Will generate:
|
|
||||||
*
|
|
||||||
* private final Titles titles = new Titles();
|
|
||||||
*
|
|
||||||
* @Override
|
|
||||||
* public GermanRelease toGerman(OriginalRelease movies) {
|
|
||||||
* if ( movies == null ) {
|
|
||||||
* return null;
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* GermanRelease germanRelease = new GermanRelease();
|
|
||||||
*
|
|
||||||
* germanRelease.setTitle( titles.translateTitleEG( movies.getTitle() ) );
|
|
||||||
*
|
|
||||||
* return germanRelease;
|
|
||||||
* }
|
|
||||||
* </code>
|
* </code>
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
* The following implementation of {@code MovieMapper} will be generated:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <code>
|
||||||
|
*
|
||||||
|
* public class MovieMapperImpl implements MovieMapper {
|
||||||
|
* private final Titles titles = new Titles();
|
||||||
|
*
|
||||||
|
* @Override
|
||||||
|
* public GermanRelease toGerman(OriginalRelease movies) {
|
||||||
|
* if ( movies == null ) {
|
||||||
|
* return null;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* GermanRelease germanRelease = new GermanRelease();
|
||||||
|
*
|
||||||
|
* germanRelease.setTitle( titles.translateTitleEG( movies.getTitle() ) );
|
||||||
|
*
|
||||||
|
* return germanRelease;
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </code>
|
||||||
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
|
* @see org.mapstruct.Mapping#qualifiedByName()
|
||||||
|
* @see IterableMapping#qualifiedByName()
|
||||||
|
* @see MapMapping#keyQualifiedByName()
|
||||||
|
* @see MapMapping#valueQualifiedByName()
|
||||||
*/
|
*/
|
||||||
@Target( { ElementType.TYPE, ElementType.METHOD } )
|
@Target( { ElementType.TYPE, ElementType.METHOD } )
|
||||||
@Retention( RetentionPolicy.RUNTIME )
|
@Retention( RetentionPolicy.RUNTIME )
|
||||||
@Qualifier
|
@Qualifier
|
||||||
public @interface Named {
|
public @interface Named {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* A name qualifying the annotated element
|
||||||
* @return the name
|
|
||||||
*/
|
*/
|
||||||
String value();
|
String value();
|
||||||
}
|
}
|
||||||
|
@ -138,11 +138,17 @@ public @interface Mapping {
|
|||||||
Class<? extends Annotation>[] qualifiedBy() default { };
|
Class<? extends Annotation>[] qualifiedBy() default { };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See: { @link #qualifiedBy() }. String form of a predefined { @link @Qualifier }. The { @link @Qualifier }
|
* String-based form of qualifiers; When looking for a suitable mapping method for a given property, MapStruct will
|
||||||
* is more verbose, but offers more flexibility in terms of for instance refactoring. At the other hand, there
|
* only consider those methods carrying directly or indirectly (i.e. on the class-level) a {@link Named} annotation
|
||||||
* is no need to define own annotations.
|
* for each of the specified qualifier names.
|
||||||
|
* <p>
|
||||||
|
* Note that annotation-based qualifiers are generally preferable as they allow more easily to find references and
|
||||||
|
* are safe for refactorings, but name-based qualifiers can be a less verbose alternative when requiring a large
|
||||||
|
* number of qualifiers as no custom annotation types are needed.
|
||||||
*
|
*
|
||||||
* @return the qualifiers
|
* @return One or more qualifier name(s)
|
||||||
|
* @see #qualifiedBy()
|
||||||
|
* @see Named
|
||||||
*/
|
*/
|
||||||
String[] qualifiedByName() default { };
|
String[] qualifiedByName() default { };
|
||||||
|
|
||||||
|
@ -136,11 +136,17 @@ public @interface Mapping {
|
|||||||
Class<? extends Annotation>[] qualifiedBy() default { };
|
Class<? extends Annotation>[] qualifiedBy() default { };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See: { @link #qualifiedBy() }. String form of a predefined { @link @Qualifier }. The { @link @Qualifier }
|
* String-based form of qualifiers; When looking for a suitable mapping method for a given property, MapStruct will
|
||||||
* is more verbose, but offers more flexibility in terms of for instance refactoring. At the other hand, there
|
* only consider those methods carrying directly or indirectly (i.e. on the class-level) a {@link Named} annotation
|
||||||
* is no need to define own annotations.
|
* for each of the specified qualifier names.
|
||||||
|
* <p>
|
||||||
|
* Note that annotation-based qualifiers are generally preferable as they allow more easily to find references and
|
||||||
|
* are safe for refactorings, but name-based qualifiers can be a less verbose alternative when requiring a large
|
||||||
|
* number of qualifiers as no custom annotation types are needed.
|
||||||
*
|
*
|
||||||
* @return the qualifiers
|
* @return One or more qualifier name(s)
|
||||||
|
* @see #qualifiedBy()
|
||||||
|
* @see Named
|
||||||
*/
|
*/
|
||||||
String[] qualifiedByName() default { };
|
String[] qualifiedByName() default { };
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user