mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#252 Renaming @ReverseMappingMethod to @InheritInverseConfiguration
* Improving error messages * Fixing some typos
This commit is contained in:
parent
5457f3583a
commit
32eeceb0cf
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Advises the code generator to apply all the {@link Mapping}s from an inverse mapping method to the annotated method
|
||||
* as well. An inverse mapping method is a method which has the annotated method's source type as target type (return
|
||||
* type or indicated through a parameter annotated with {@link MappingTarget}) and the annotated method's target type as
|
||||
* source type.
|
||||
* <p>
|
||||
* Any mappings given on the annotated method itself are added to those mappings inherited from the inverse method. In
|
||||
* case of a conflict local mappings take precedence over inherited mappings.
|
||||
* <p>
|
||||
* If more than one matching inverse method exists, the name of the method to inherit the configuration from must be
|
||||
* specified via {@link #name()}
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@Target( ElementType.METHOD )
|
||||
@Retention( RetentionPolicy.SOURCE )
|
||||
public @interface InheritInverseConfiguration {
|
||||
|
||||
/**
|
||||
* The name of the inverse mapping method to inherit the mappings from. Needs only to be specified in case more than
|
||||
* one inverse method with matching source and target type exists.
|
||||
*
|
||||
* @return The name of the inverse mapping method to inherit the mappings from.
|
||||
*/
|
||||
String name() default "";
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
/**
|
||||
* Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||
* and/or other contributors as indicated by the @authors tag. See the
|
||||
* copyright.txt file in the distribution for a full listing of all
|
||||
* contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.mapstruct;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation ensures that all forward mappings are copied as a base for the reverse mapping.
|
||||
*
|
||||
* MapStruct will check if there is a source / target mapper matching the profile. That is:
|
||||
* <ol>
|
||||
* <li>the source parameter should match the return type (or the parameter indicated as {@link MappingTarget}</li>
|
||||
* <li>the target parameter should match the source parameter</li>
|
||||
* </ol>
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface ReverseMappingMethod {
|
||||
|
||||
/**
|
||||
* The name of the 'forward' mapping method that should be taken as the base.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String configuredBy() default "";
|
||||
|
||||
}
|
@ -21,7 +21,7 @@ package org.mapstruct.itest.simple;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
@ -35,6 +35,6 @@ public interface SourceTargetMapper {
|
||||
})
|
||||
Target sourceToTarget(Source source);
|
||||
|
||||
@ReverseMappingMethod
|
||||
@InheritInverseConfiguration
|
||||
Source targetToSource(Target target);
|
||||
}
|
||||
|
@ -22,7 +22,9 @@ import javax.xml.bind.annotation.XmlElementDecl;
|
||||
|
||||
import net.java.dev.hickory.prism.GeneratePrism;
|
||||
import net.java.dev.hickory.prism.GeneratePrisms;
|
||||
|
||||
import org.mapstruct.DecoratedWith;
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.IterableMapping;
|
||||
import org.mapstruct.MapMapping;
|
||||
import org.mapstruct.Mapper;
|
||||
@ -30,7 +32,6 @@ import org.mapstruct.MapperConfig;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.TargetType;
|
||||
|
||||
/**
|
||||
@ -48,7 +49,7 @@ import org.mapstruct.TargetType;
|
||||
@GeneratePrism(value = MappingTarget.class, publicAccess = true),
|
||||
@GeneratePrism(value = DecoratedWith.class, publicAccess = true),
|
||||
@GeneratePrism(value = MapperConfig.class, publicAccess = true),
|
||||
@GeneratePrism(value = ReverseMappingMethod.class, publicAccess = true),
|
||||
@GeneratePrism(value = InheritInverseConfiguration.class, publicAccess = true),
|
||||
|
||||
// external types
|
||||
@GeneratePrism(value = XmlElementDecl.class, publicAccess = true)
|
||||
|
@ -25,6 +25,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
@ -53,8 +54,8 @@ import org.mapstruct.ap.model.source.Mapping;
|
||||
import org.mapstruct.ap.model.source.SourceMethod;
|
||||
import org.mapstruct.ap.option.Options;
|
||||
import org.mapstruct.ap.prism.DecoratedWithPrism;
|
||||
import org.mapstruct.ap.prism.InheritInverseConfigurationPrism;
|
||||
import org.mapstruct.ap.prism.MapperPrism;
|
||||
import org.mapstruct.ap.prism.ReverseMappingMethodPrism;
|
||||
import org.mapstruct.ap.processor.creation.MappingResolverImpl;
|
||||
import org.mapstruct.ap.util.MapperConfig;
|
||||
import org.mapstruct.ap.util.Strings;
|
||||
@ -410,7 +411,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
|
||||
SourceMethod result = null;
|
||||
|
||||
ReverseMappingMethodPrism reversePrism = ReverseMappingMethodPrism.getInstanceOn( method.getExecutable() );
|
||||
InheritInverseConfigurationPrism reversePrism = InheritInverseConfigurationPrism.getInstanceOn( method.getExecutable() );
|
||||
if ( reversePrism != null ) {
|
||||
|
||||
// method is configured as being reverse method, collect candidates
|
||||
@ -421,17 +422,17 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
}
|
||||
}
|
||||
|
||||
String configuredBy = reversePrism.configuredBy();
|
||||
String name = reversePrism.name();
|
||||
if ( candidates.size() == 1 ) {
|
||||
// no ambiguity: if no configuredBy is specified, or configuredBy specified and match
|
||||
if ( configuredBy.isEmpty() ) {
|
||||
if ( name.isEmpty() ) {
|
||||
result = candidates.get( 0 );
|
||||
}
|
||||
else if ( candidates.get( 0 ).getName().equals( configuredBy ) ) {
|
||||
else if ( candidates.get( 0 ).getName().equals( name ) ) {
|
||||
result = candidates.get( 0 );
|
||||
}
|
||||
else {
|
||||
reportErrorWhenNonMatchingConfiguredBy( candidates.get( 0 ), method, reversePrism );
|
||||
reportErrorWhenNonMatchingName( candidates.get( 0 ), method, reversePrism );
|
||||
}
|
||||
}
|
||||
else if ( candidates.size() > 1 ) {
|
||||
@ -439,7 +440,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
|
||||
List<SourceMethod> nameFilteredcandidates = new ArrayList<SourceMethod>();
|
||||
for ( SourceMethod candidate : candidates ) {
|
||||
if ( candidate.getName().equals( configuredBy ) ) {
|
||||
if ( candidate.getName().equals( name ) ) {
|
||||
nameFilteredcandidates.add( candidate );
|
||||
}
|
||||
}
|
||||
@ -448,7 +449,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
result = nameFilteredcandidates.get( 0 );
|
||||
}
|
||||
else if ( nameFilteredcandidates.size() > 1 ) {
|
||||
reportErrorWhenMoreConfiguredByMatch( nameFilteredcandidates, method, reversePrism );
|
||||
reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, reversePrism );
|
||||
}
|
||||
|
||||
if ( result == null ) {
|
||||
@ -457,21 +458,21 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
}
|
||||
|
||||
if ( result != null ) {
|
||||
reportErrorIfForwardMethodHasReverseMappingMethodAnnotation( result, method, reversePrism );
|
||||
reportErrorIfForwardMethodHasInheritInverseConfigurationAnnotation( result, method, reversePrism );
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void reportErrorIfForwardMethodHasReverseMappingMethodAnnotation( SourceMethod candidate,
|
||||
SourceMethod method, ReverseMappingMethodPrism reversePrism ) {
|
||||
private void reportErrorIfForwardMethodHasInheritInverseConfigurationAnnotation( SourceMethod candidate,
|
||||
SourceMethod method, InheritInverseConfigurationPrism reversePrism ) {
|
||||
|
||||
ReverseMappingMethodPrism candidatePrism = ReverseMappingMethodPrism.getInstanceOn( candidate.getExecutable() );
|
||||
InheritInverseConfigurationPrism candidatePrism = InheritInverseConfigurationPrism.getInstanceOn( candidate.getExecutable() );
|
||||
if ( candidatePrism != null ) {
|
||||
messager.printMessage( Diagnostic.Kind.ERROR,
|
||||
String.format( "Resolved reverse mapping: \"%s\" should not carry the @ReverseMappingMethod "
|
||||
+ "annotation itself.",
|
||||
String.format( "Resolved inverse mapping method %s() should not carry the "
|
||||
+ "@InheritInverseConfiguration annotation itself.",
|
||||
candidate.getName()
|
||||
),
|
||||
method.getExecutable(),
|
||||
@ -480,49 +481,49 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
}
|
||||
|
||||
private void reportErrorWhenAmbigousReverseMapping( List<SourceMethod> candidates, SourceMethod method,
|
||||
ReverseMappingMethodPrism reversePrism ) {
|
||||
InheritInverseConfigurationPrism reversePrism ) {
|
||||
|
||||
List<String> candidateNames = new ArrayList<String>();
|
||||
for (SourceMethod candidate : candidates ) {
|
||||
candidateNames.add( candidate.getName() );
|
||||
}
|
||||
|
||||
String configuredBy = reversePrism.configuredBy();
|
||||
if ( configuredBy.isEmpty() ) {
|
||||
String name = reversePrism.name();
|
||||
if ( name.isEmpty() ) {
|
||||
messager.printMessage( Diagnostic.Kind.ERROR,
|
||||
String.format( "None of the candidates \"%s\" matches. Consider specifiying 'configuredBy'.",
|
||||
Strings.join( candidateNames, "," )
|
||||
String.format( "Several matching inverse methods exist: %s(). Specify a name explicitly.",
|
||||
Strings.join( candidateNames, "(), " )
|
||||
),
|
||||
method.getExecutable(),
|
||||
reversePrism.mirror );
|
||||
}
|
||||
else {
|
||||
messager.printMessage( Diagnostic.Kind.ERROR,
|
||||
String.format( "None of the candidates \"%s\", matches configuredBy: \"blah\".",
|
||||
Strings.join( candidateNames, "," ), configuredBy
|
||||
String.format( "None of the candidates %s() matches given name: \"%s\".",
|
||||
Strings.join( candidateNames, "(), " ), name
|
||||
),
|
||||
method.getExecutable(),
|
||||
reversePrism.mirror );
|
||||
}
|
||||
}
|
||||
|
||||
private void reportErrorWhenMoreConfiguredByMatch(List<SourceMethod> candidates, SourceMethod method,
|
||||
ReverseMappingMethodPrism reversePrism ) {
|
||||
private void reportErrorWhenSeveralNamesMatch(List<SourceMethod> candidates, SourceMethod method,
|
||||
InheritInverseConfigurationPrism reversePrism ) {
|
||||
|
||||
messager.printMessage( Diagnostic.Kind.ERROR,
|
||||
String.format( "ConfiguredBy: \"%s\" matches more candidates: \"%s\".",
|
||||
Strings.join( candidates, "," ), reversePrism.configuredBy()
|
||||
String.format( "Given name \"%s\" matches several candidate methods: %s().",
|
||||
reversePrism.name(), Strings.join( candidates, "(), " )
|
||||
),
|
||||
method.getExecutable(),
|
||||
reversePrism.mirror );
|
||||
}
|
||||
|
||||
private void reportErrorWhenNonMatchingConfiguredBy(SourceMethod onlyCandidate, SourceMethod method,
|
||||
ReverseMappingMethodPrism reversePrism ) {
|
||||
private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method,
|
||||
InheritInverseConfigurationPrism reversePrism ) {
|
||||
|
||||
messager.printMessage( Diagnostic.Kind.ERROR,
|
||||
String.format( "ConfiguredBy: \"%s\" does not match the only candidate. Did you mean: \"%s\".",
|
||||
reversePrism.configuredBy(), onlyCandidate.getName()
|
||||
String.format( "Given name \"%s\" does not match the only candidate. Did you mean: \"%s\".",
|
||||
reversePrism.name(), onlyCandidate.getName()
|
||||
),
|
||||
method.getExecutable(),
|
||||
reversePrism.mirror );
|
||||
|
@ -24,7 +24,7 @@ import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
@ -39,7 +39,8 @@ public interface SourceTargetMapper {
|
||||
@Mapping(source = "stringList2", target = "stringListNoSetter")
|
||||
})
|
||||
Target sourceToTarget(Source source);
|
||||
@ReverseMappingMethod(configuredBy = "sourceToTarget")
|
||||
|
||||
@InheritInverseConfiguration( name = "sourceToTarget" )
|
||||
Source targetToSource(Target target);
|
||||
|
||||
@Mappings({
|
||||
@ -51,11 +52,13 @@ public interface SourceTargetMapper {
|
||||
Target sourceToTargetTwoArg(Source source, @MappingTarget Target target);
|
||||
|
||||
Set<String> integerSetToStringSet(Set<Integer> integers);
|
||||
@ReverseMappingMethod
|
||||
|
||||
@InheritInverseConfiguration
|
||||
Set<Integer> stringSetToIntegerSet(Set<String> strings);
|
||||
|
||||
Set<String> colourSetToStringSet(Set<Colour> colours);
|
||||
@ReverseMappingMethod
|
||||
|
||||
@InheritInverseConfiguration
|
||||
Set<Colour> stringSetToColourSet(Set<String> colours);
|
||||
|
||||
Set<Number> integerSetToNumberSet(Set<Integer> integers);
|
||||
|
@ -24,7 +24,7 @@ import java.util.Map;
|
||||
import org.mapstruct.MapMapping;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper(uses = CustomNumberMapper.class)
|
||||
@ -34,7 +34,7 @@ public interface SourceTargetMapper {
|
||||
|
||||
@MapMapping(valueDateFormat = "dd.MM.yyyy")
|
||||
Map<String, String> longDateMapToStringStringMap(Map<Long, Date> source);
|
||||
@ReverseMappingMethod
|
||||
@InheritInverseConfiguration
|
||||
Map<Long, Date> stringStringMapToLongDateMap(Map<String, String> source);
|
||||
|
||||
@MapMapping(valueDateFormat = "dd.MM.yyyy")
|
||||
@ -46,7 +46,7 @@ public interface SourceTargetMapper {
|
||||
@MappingTarget Map<Long, Date> target);
|
||||
|
||||
Target sourceToTarget(Source source);
|
||||
@ReverseMappingMethod
|
||||
@InheritInverseConfiguration
|
||||
Source targetToSource(Target target);
|
||||
|
||||
Map<Number, Number> intIntToNumberNumberMap(Map<Integer, Integer> source);
|
||||
|
@ -23,7 +23,7 @@ import java.util.List;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.ap.test.complex.other.DateMapper;
|
||||
import org.mapstruct.ap.test.complex.source.Car;
|
||||
import org.mapstruct.ap.test.complex.source.Person;
|
||||
@ -41,18 +41,18 @@ public interface CarMapper {
|
||||
@Mapping(source = "manufacturingDate", target = "manufacturingYear")
|
||||
})
|
||||
CarDto carToCarDto(Car car);
|
||||
@ReverseMappingMethod
|
||||
@InheritInverseConfiguration
|
||||
Car carDtoToCar(CarDto carDto);
|
||||
|
||||
List<CarDto> carsToCarDtos(List<Car> cars);
|
||||
@ReverseMappingMethod
|
||||
@InheritInverseConfiguration
|
||||
List<Car> carDtosToCars(List<CarDto> carDtos);
|
||||
|
||||
PersonDto personToPersonDto(Person person);
|
||||
@ReverseMappingMethod
|
||||
@InheritInverseConfiguration
|
||||
Person personDtoToPerson(PersonDto personDto);
|
||||
|
||||
List<PersonDto> personsToPersonDtos(List<Person> persons);
|
||||
@ReverseMappingMethod
|
||||
@InheritInverseConfiguration
|
||||
List<Person> personDtosToPersons(List<PersonDto> personDtos);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ package org.mapstruct.ap.test.conversion;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
@ -34,6 +34,6 @@ public interface SourceTargetMapper {
|
||||
@Mapping(source = "baz", target = "qax")
|
||||
})
|
||||
Target sourceToTarget(Source source);
|
||||
@ReverseMappingMethod
|
||||
@InheritInverseConfiguration
|
||||
Source targetToSource(Target target);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import java.util.List;
|
||||
import org.mapstruct.IterableMapping;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
@ -34,11 +34,11 @@ public interface SourceTargetMapper {
|
||||
|
||||
@Mapping(source = "date", dateFormat = "dd.MM.yyyy")
|
||||
Target sourceToTarget(Source source);
|
||||
@ReverseMappingMethod
|
||||
@InheritInverseConfiguration
|
||||
Source targetToSource(Target target);
|
||||
|
||||
@IterableMapping(dateFormat = "dd.MM.yyyy")
|
||||
List<String> stringListToDateList(List<Date> dates);
|
||||
@ReverseMappingMethod
|
||||
@InheritInverseConfiguration
|
||||
List<Date> dateListToStringList(List<String> strings);
|
||||
}
|
||||
|
@ -18,10 +18,10 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.conversion.java8time;
|
||||
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
@ -81,6 +81,6 @@ public interface SourceTargetMapper {
|
||||
@Mapping( source = "localTime", dateFormat = LOCAL_TIME_FORMAT )
|
||||
Source targetToSourceLocalTimeMapped(Target target);
|
||||
|
||||
@ReverseMappingMethod(configuredBy = "sourceToTarget")
|
||||
@InheritInverseConfiguration( name = "sourceToTarget" )
|
||||
Source targetToSourceDefaultMapping(Target target);
|
||||
}
|
||||
|
@ -18,10 +18,10 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.conversion.jodatime;
|
||||
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
@ -45,7 +45,7 @@ public interface SourceTargetMapper {
|
||||
})
|
||||
Target sourceToTarget(Source source);
|
||||
|
||||
@ReverseMappingMethod(configuredBy = "targetToSource") // TODO: FIXME
|
||||
@InheritInverseConfiguration( name = "targetToSource" ) // TODO: FIXME
|
||||
Target sourceToTargetDefaultMapping(Source source);
|
||||
|
||||
@Mapping(source = "dateTime", dateFormat = DATE_TIME_FORMAT)
|
||||
@ -81,6 +81,6 @@ public interface SourceTargetMapper {
|
||||
@Mapping(source = "localTime", dateFormat = LOCAL_TIME_FORMAT)
|
||||
Source targetToSourceLocalTimeMapped(Target target);
|
||||
|
||||
@ReverseMappingMethod(configuredBy = "sourceToTarget") // TODO: FIXME
|
||||
@InheritInverseConfiguration( name = "sourceToTarget" ) // TODO: FIXME
|
||||
Source targetToSourceDefaultMapping(Target target);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ package org.mapstruct.ap.test.ignore;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
@ -34,6 +34,6 @@ public interface AnimalMapper {
|
||||
@Mapping(target = "age", ignore = true)
|
||||
})
|
||||
AnimalDto animalToDto(Animal animal);
|
||||
@ReverseMappingMethod
|
||||
@InheritInverseConfiguration
|
||||
Animal animalDtoToAnimal(AnimalDto animalDto);
|
||||
}
|
||||
|
@ -18,8 +18,10 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.reverse;
|
||||
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
@ -36,11 +38,11 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||
@IssueKey( "252" )
|
||||
@WithClasses( { Source.class, Target.class } )
|
||||
@RunWith( AnnotationProcessorTestRunner.class )
|
||||
public class ReverseMappingMethodTest {
|
||||
public class InheritInverseConfigurationTest {
|
||||
|
||||
@Test
|
||||
@WithClasses( { SourceTargetMapper.class } )
|
||||
public void shouldReverseMappingMethodMultipleCandidates() {
|
||||
public void shouldInheritInverseConfigurationMultipleCandidates() {
|
||||
|
||||
Source source = new Source();
|
||||
source.setPropertyToIgnoreDownstream( "propToIgnoreDownStream" );
|
||||
@ -59,67 +61,65 @@ public class ReverseMappingMethodTest {
|
||||
assertThat( source.getIntegerPropX() ).isEqualTo( 2 );
|
||||
assertThat( source.getSomeConstantDownstream() ).isEqualTo( "test" );
|
||||
assertThat( source.getPropertyToIgnoreDownstream() ).isNull();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithClasses( { SourceTargetMapperAmbigious1.class } )
|
||||
@WithClasses( { SourceTargetMapperAmbiguous1.class } )
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic( type = SourceTargetMapperAmbigious1.class,
|
||||
@Diagnostic( type = SourceTargetMapperAmbiguous1.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 51,
|
||||
messageRegExp = "None of the candidates \"forward,forwardNotToReverse\" matches. "
|
||||
+ "Consider specifiying 'configuredBy'." ),
|
||||
@Diagnostic( type = SourceTargetMapperAmbigious1.class,
|
||||
messageRegExp = "Several matching inverse methods exist: forward\\(\\), "
|
||||
+ "forwardNotToReverse\\(\\). Specify a name explicitly." ),
|
||||
@Diagnostic( type = SourceTargetMapperAmbiguous1.class,
|
||||
kind = Kind.WARNING,
|
||||
line = 56,
|
||||
messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"" )
|
||||
}
|
||||
)
|
||||
public void shouldRaiseAmbigousReverseMethodError() {
|
||||
public void shouldRaiseAmbiguousReverseMethodError() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithClasses( { SourceTargetMapperAmbigious2.class } )
|
||||
@WithClasses( { SourceTargetMapperAmbiguous2.class } )
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic( type = SourceTargetMapperAmbigious2.class,
|
||||
@Diagnostic( type = SourceTargetMapperAmbiguous2.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 51,
|
||||
messageRegExp = "None of the candidates \"forward,forwardNotToReverse\", matches configuredBy: "
|
||||
+ "\"blah\"." ),
|
||||
@Diagnostic( type = SourceTargetMapperAmbigious2.class,
|
||||
messageRegExp = "None of the candidates forward\\(\\), forwardNotToReverse\\(\\) matches given "
|
||||
+ "name: \"blah\"." ),
|
||||
@Diagnostic( type = SourceTargetMapperAmbiguous2.class,
|
||||
kind = Kind.WARNING,
|
||||
line = 56,
|
||||
messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"" )
|
||||
}
|
||||
)
|
||||
public void shouldRaiseAmbigousReverseMethodErrorWrongName() {
|
||||
public void shouldRaiseAmbiguousReverseMethodErrorWrongName() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithClasses( { SourceTargetMapperAmbigious3.class } )
|
||||
@WithClasses( { SourceTargetMapperAmbiguous3.class } )
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic( type = SourceTargetMapperAmbigious3.class,
|
||||
@Diagnostic( type = SourceTargetMapperAmbiguous3.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 52,
|
||||
messageRegExp = "ConfiguredBy:.*forward.*forward.*@MappingTarget.*matches more candidates:"
|
||||
+ " \"forward\"." ),
|
||||
@Diagnostic( type = SourceTargetMapperAmbigious3.class,
|
||||
messageRegExp = "Given name \"forward\" matches several candidate methods: .*forward.*\\(\\), "
|
||||
+ ".*forward.*\\(\\)" ),
|
||||
@Diagnostic( type = SourceTargetMapperAmbiguous3.class,
|
||||
kind = Kind.WARNING,
|
||||
line = 57,
|
||||
messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"" )
|
||||
}
|
||||
)
|
||||
public void shouldRaiseAmbigousReverseMethodErrorDuplicatedName() {
|
||||
public void shouldRaiseAmbiguousReverseMethodErrorDuplicatedName() {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@WithClasses( { SourceTargetMapperErroneouslyAnnotated.class } )
|
||||
@ExpectedCompilationOutcome(
|
||||
@ -128,8 +128,8 @@ public class ReverseMappingMethodTest {
|
||||
@Diagnostic( type = SourceTargetMapperErroneouslyAnnotated.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 51,
|
||||
messageRegExp = "Resolved reverse mapping: \"reverse\" should not carry the "
|
||||
+ "@ReverseMappingMethod annotation itself." )
|
||||
messageRegExp = "Resolved inverse mapping method reverse\\(\\) should not carry the "
|
||||
+ "@InheritInverseConfiguration annotation itself." )
|
||||
}
|
||||
)
|
||||
public void shouldUseWronglyAnnotatedError() {
|
||||
@ -143,7 +143,7 @@ public class ReverseMappingMethodTest {
|
||||
@Diagnostic( type = SourceTargetMapperNonMatchingName.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 44,
|
||||
messageRegExp = "ConfiguredBy: \"blah\" does not match the only candidate. Did you mean: "
|
||||
messageRegExp = "Given name \"blah\" does not match the only candidate. Did you mean: "
|
||||
+ "\"forward\"." ),
|
||||
@Diagnostic( type = SourceTargetMapperNonMatchingName.class,
|
||||
kind = Kind.WARNING,
|
||||
@ -151,7 +151,6 @@ public class ReverseMappingMethodTest {
|
||||
messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"" )
|
||||
}
|
||||
)
|
||||
public void shouldAdviceOnSpecifyingCorrectName() {
|
||||
public void shouldAdviseOnSpecifyingCorrectName() {
|
||||
}
|
||||
|
||||
}
|
@ -18,10 +18,10 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.reverse;
|
||||
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
@ -48,7 +48,7 @@ public interface SourceTargetMapper {
|
||||
} )
|
||||
Target forwardNotToReverse( Source source );
|
||||
|
||||
@ReverseMappingMethod(configuredBy = "forward")
|
||||
@InheritInverseConfiguration( name = "forward" )
|
||||
@Mappings( {
|
||||
@Mapping( target = "someConstantDownstream", constant = "test" ),
|
||||
@Mapping( source = "propertyToIgnoreDownstream", ignore = true )
|
||||
|
@ -21,7 +21,7 @@ package org.mapstruct.ap.test.reverse;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
@ -30,9 +30,9 @@ import org.mapstruct.factory.Mappers;
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
public interface SourceTargetMapperAmbigious1 {
|
||||
public interface SourceTargetMapperAmbiguous1 {
|
||||
|
||||
SourceTargetMapperAmbigious1 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbigious1.class );
|
||||
SourceTargetMapperAmbiguous1 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbiguous1.class );
|
||||
|
||||
@Mappings( {
|
||||
@Mapping( source = "stringPropX", target = "stringPropY" ),
|
||||
@ -48,7 +48,7 @@ public interface SourceTargetMapperAmbigious1 {
|
||||
} )
|
||||
Target forwardNotToReverse( Source source );
|
||||
|
||||
@ReverseMappingMethod
|
||||
@InheritInverseConfiguration
|
||||
@Mappings( {
|
||||
@Mapping( target = "someConstantDownstream", constant = "test" ),
|
||||
@Mapping( source = "propertyToIgnoreDownstream", ignore = true )
|
@ -18,10 +18,10 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.reverse;
|
||||
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
@ -30,9 +30,9 @@ import org.mapstruct.factory.Mappers;
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
public interface SourceTargetMapperAmbigious2 {
|
||||
public interface SourceTargetMapperAmbiguous2 {
|
||||
|
||||
SourceTargetMapperAmbigious2 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbigious2.class );
|
||||
SourceTargetMapperAmbiguous2 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbiguous2.class );
|
||||
|
||||
@Mappings( {
|
||||
@Mapping( source = "stringPropX", target = "stringPropY" ),
|
||||
@ -48,7 +48,7 @@ public interface SourceTargetMapperAmbigious2 {
|
||||
} )
|
||||
Target forwardNotToReverse( Source source );
|
||||
|
||||
@ReverseMappingMethod(configuredBy = "blah")
|
||||
@InheritInverseConfiguration( name = "blah" )
|
||||
@Mappings( {
|
||||
@Mapping( target = "someConstantDownstream", constant = "test" ),
|
||||
@Mapping( source = "propertyToIgnoreDownstream", ignore = true )
|
@ -18,11 +18,11 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.reverse;
|
||||
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
@ -31,9 +31,9 @@ import org.mapstruct.factory.Mappers;
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
public interface SourceTargetMapperAmbigious3 {
|
||||
public interface SourceTargetMapperAmbiguous3 {
|
||||
|
||||
SourceTargetMapperAmbigious3 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbigious3.class );
|
||||
SourceTargetMapperAmbiguous3 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbiguous3.class );
|
||||
|
||||
@Mappings( {
|
||||
@Mapping( source = "stringPropX", target = "stringPropY" ),
|
||||
@ -49,7 +49,7 @@ public interface SourceTargetMapperAmbigious3 {
|
||||
} )
|
||||
Target forward( Source source, @MappingTarget Target target );
|
||||
|
||||
@ReverseMappingMethod(configuredBy = "forward")
|
||||
@InheritInverseConfiguration( name = "forward" )
|
||||
@Mappings( {
|
||||
@Mapping( target = "someConstantDownstream", constant = "test" ),
|
||||
@Mapping( source = "propertyToIgnoreDownstream", ignore = true )
|
@ -18,10 +18,10 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.reverse;
|
||||
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
@ -41,14 +41,14 @@ public interface SourceTargetMapperErroneouslyAnnotated {
|
||||
} )
|
||||
Target forward( Source source );
|
||||
|
||||
@ReverseMappingMethod(configuredBy = "forward")
|
||||
@InheritInverseConfiguration( name = "forward" )
|
||||
@Mappings( {
|
||||
@Mapping( target = "someConstantDownstream", constant = "test" ),
|
||||
@Mapping( source = "propertyToIgnoreDownstream", ignore = true )
|
||||
} )
|
||||
Source reverse( Target target );
|
||||
|
||||
@ReverseMappingMethod(configuredBy = "reverse")
|
||||
@InheritInverseConfiguration( name = "reverse" )
|
||||
@Mappings( {
|
||||
@Mapping( source = "stringPropX", target = "stringPropY" ),
|
||||
@Mapping( source = "integerPropX", target = "integerPropY" ),
|
||||
|
@ -18,10 +18,10 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.reverse;
|
||||
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.ReverseMappingMethod;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
@ -41,7 +41,7 @@ public interface SourceTargetMapperNonMatchingName {
|
||||
} )
|
||||
Target forward( Source source );
|
||||
|
||||
@ReverseMappingMethod(configuredBy = "blah")
|
||||
@InheritInverseConfiguration( name = "blah" )
|
||||
@Mappings( {
|
||||
@Mapping( target = "someConstantDownstream", constant = "test" ),
|
||||
@Mapping( source = "propertyToIgnoreDownstream", ignore = true )
|
||||
|
Loading…
x
Reference in New Issue
Block a user