|
21 | 21 |
|
22 | 22 | import org.mapstruct.ap.internal.gem.BeanMappingGem; |
23 | 23 | import org.mapstruct.ap.internal.gem.ConditionGem; |
| 24 | +import org.mapstruct.ap.internal.gem.IgnoredGem; |
| 25 | +import org.mapstruct.ap.internal.gem.IgnoredsGem; |
24 | 26 | import org.mapstruct.ap.internal.gem.IterableMappingGem; |
25 | 27 | import org.mapstruct.ap.internal.gem.MapMappingGem; |
26 | 28 | import org.mapstruct.ap.internal.gem.MappingGem; |
@@ -76,6 +78,8 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis |
76 | 78 | private static final String VALUE_MAPPING_FQN = "org.mapstruct.ValueMapping"; |
77 | 79 | private static final String VALUE_MAPPINGS_FQN = "org.mapstruct.ValueMappings"; |
78 | 80 | private static final String CONDITION_FQN = "org.mapstruct.Condition"; |
| 81 | + private static final String IGNORED_FQN = "org.mapstruct.Ignored"; |
| 82 | + private static final String IGNOREDS_FQN = "org.mapstruct.Ignoreds"; |
79 | 83 | private FormattingMessager messager; |
80 | 84 | private TypeFactory typeFactory; |
81 | 85 | private AccessorNamingUtils accessorNaming; |
@@ -619,7 +623,10 @@ private boolean isStreamTypeOrIterableFromJavaStdLib(Type type) { |
619 | 623 | * @return The mappings for the given method, keyed by target property name |
620 | 624 | */ |
621 | 625 | private Set<MappingOptions> getMappings(ExecutableElement method, BeanMappingOptions beanMapping) { |
622 | | - return new RepeatableMappings( beanMapping ).getProcessedAnnotations( method ); |
| 626 | + Set<MappingOptions> processedAnnotations = new RepeatableMappings( beanMapping ) |
| 627 | + .getProcessedAnnotations( method ); |
| 628 | + processedAnnotations.addAll( new IgnoredConditions().getProcessedAnnotations( method ) ); |
| 629 | + return processedAnnotations; |
623 | 630 | } |
624 | 631 |
|
625 | 632 | /** |
@@ -818,4 +825,50 @@ protected void addInstance(ConditionGem gem, Element source, Set<ConditionOption |
818 | 825 | } |
819 | 826 | } |
820 | 827 | } |
| 828 | + |
| 829 | + private class IgnoredConditions extends RepeatableAnnotations<IgnoredGem, IgnoredsGem, MappingOptions> { |
| 830 | + |
| 831 | + protected IgnoredConditions() { |
| 832 | + super( elementUtils, IGNORED_FQN, IGNOREDS_FQN ); |
| 833 | + } |
| 834 | + |
| 835 | + @Override |
| 836 | + protected IgnoredGem singularInstanceOn(Element element) { |
| 837 | + return IgnoredGem.instanceOn( element ); |
| 838 | + } |
| 839 | + |
| 840 | + @Override |
| 841 | + protected IgnoredsGem multipleInstanceOn(Element element) { |
| 842 | + return IgnoredsGem.instanceOn( element ); |
| 843 | + } |
| 844 | + |
| 845 | + @Override |
| 846 | + protected void addInstance(IgnoredGem gem, Element method, Set<MappingOptions> mappings) { |
| 847 | + IgnoredGem ignoredGem = IgnoredGem.instanceOn( method ); |
| 848 | + if ( ignoredGem == null ) { |
| 849 | + ignoredGem = gem; |
| 850 | + } |
| 851 | + String prefix = ignoredGem.prefix().get(); |
| 852 | + for ( String target : ignoredGem.targets().get() ) { |
| 853 | + String realTarget = target; |
| 854 | + if ( !prefix.isEmpty() ) { |
| 855 | + realTarget = prefix + "." + target; |
| 856 | + } |
| 857 | + MappingOptions mappingOptions = MappingOptions.forIgnore( realTarget ); |
| 858 | + if ( mappings.contains( mappingOptions ) ) { |
| 859 | + messager.printMessage( method, Message.PROPERTYMAPPING_DUPLICATE_TARGETS, realTarget ); |
| 860 | + } |
| 861 | + mappings.add( mappingOptions ); |
| 862 | + } |
| 863 | + } |
| 864 | + |
| 865 | + @Override |
| 866 | + protected void addInstances(IgnoredsGem gem, Element method, Set<MappingOptions> mappings) { |
| 867 | + IgnoredsGem ignoredsGem = IgnoredsGem.instanceOn( method ); |
| 868 | + for ( IgnoredGem ignoredGem : ignoredsGem.value().get() ) { |
| 869 | + addInstance( ignoredGem, method, mappings ); |
| 870 | + } |
| 871 | + } |
| 872 | + } |
| 873 | + |
821 | 874 | } |
0 commit comments