forked from mapstruct/mapstruct
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTargetType.java
More file actions
53 lines (51 loc) · 1.57 KB
/
TargetType.java
File metadata and controls
53 lines (51 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Declares a parameter of a custom mapping method to be populated with the target type of the mapping.
* <p>
* Not more than one parameter can be declared as {@code TargetType} and that parameter needs to be of type
* {@link Class} (may be parameterized), or a super-type of it.
*
* <p>
* <strong>Example:</strong>
* </p>
* <pre><code class='java'>
* public class EntityFactory {
* public <T extends BaseEntity> T createEntity(@TargetType Class<T> entityClass) {
* return // ... custom factory logic
* }
* }
* @Mapper(uses = EntityFactory.class)
* public interface CarMapper {
* CarEntity carDtoToCar(CarDto dto);
* }
* </code></pre>
* <pre><code class='java'>
* // generates
* public class CarMapperImpl implements CarMapper {
* private final EntityFactory entityFactory = new EntityFactory();
* @Override
* public CarEntity carDtoToCar(CarDto dto) {
* if ( dto == null ) {
* return null;
* }
* CarEntity carEntity = entityFactory.createEntity( CarEntity.class );
* return carEntity;
* }
* }
* </code></pre>
*
* @author Andreas Gudian
*/
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.CLASS)
public @interface TargetType {
}