diff --git a/core-common/src/main/java/org/mapstruct/InheritInverseConfiguration.java b/core-common/src/main/java/org/mapstruct/InheritInverseConfiguration.java
new file mode 100644
index 000000000..79c5c256c
--- /dev/null
+++ b/core-common/src/main/java/org/mapstruct/InheritInverseConfiguration.java
@@ -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.
+ *
+ * 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.
+ *
+ * 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 "";
+}
diff --git a/core-common/src/main/java/org/mapstruct/ReverseMappingMethod.java b/core-common/src/main/java/org/mapstruct/ReverseMappingMethod.java
deleted file mode 100644
index 5aa401524..000000000
--- a/core-common/src/main/java/org/mapstruct/ReverseMappingMethod.java
+++ /dev/null
@@ -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:
- *
- * - the source parameter should match the return type (or the parameter indicated as {@link MappingTarget}
- * - the target parameter should match the source parameter
- *
- *
- * @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 "";
-
-}
diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java
index 7b1bdcc5f..da433a54b 100644
--- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java
+++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java
@@ -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);
}
diff --git a/processor/src/main/java/org/mapstruct/ap/prism/PrismGenerator.java b/processor/src/main/java/org/mapstruct/ap/prism/PrismGenerator.java
index 0437b0259..906fd9cd0 100644
--- a/processor/src/main/java/org/mapstruct/ap/prism/PrismGenerator.java
+++ b/processor/src/main/java/org/mapstruct/ap/prism/PrismGenerator.java
@@ -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)
diff --git a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java
index 4cde54e30..612e49a2d 100644
--- a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java
+++ b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java
@@ -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 1 ) {
@@ -439,7 +440,7 @@ public class MapperCreationProcessor implements ModelElementProcessor nameFilteredcandidates = new ArrayList();
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 1 ) {
- reportErrorWhenMoreConfiguredByMatch( nameFilteredcandidates, method, reversePrism );
+ reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, reversePrism );
}
if ( result == null ) {
@@ -457,21 +458,21 @@ public class MapperCreationProcessor implements ModelElementProcessor candidates, SourceMethod method,
- ReverseMappingMethodPrism reversePrism ) {
+ InheritInverseConfigurationPrism reversePrism ) {
List candidateNames = new ArrayList();
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 candidates, SourceMethod method,
- ReverseMappingMethodPrism reversePrism ) {
+ private void reportErrorWhenSeveralNamesMatch(List 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 );
diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java
index bdd1306d8..d6a2a79f7 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java
@@ -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 integerSetToStringSet(Set integers);
- @ReverseMappingMethod
+
+ @InheritInverseConfiguration
Set stringSetToIntegerSet(Set strings);
Set colourSetToStringSet(Set colours);
- @ReverseMappingMethod
+
+ @InheritInverseConfiguration
Set stringSetToColourSet(Set colours);
Set integerSetToNumberSet(Set integers);
diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/SourceTargetMapper.java
index 4811d8d07..febee7b14 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/SourceTargetMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/SourceTargetMapper.java
@@ -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 longDateMapToStringStringMap(Map source);
- @ReverseMappingMethod
+ @InheritInverseConfiguration
Map stringStringMapToLongDateMap(Map source);
@MapMapping(valueDateFormat = "dd.MM.yyyy")
@@ -46,7 +46,7 @@ public interface SourceTargetMapper {
@MappingTarget Map target);
Target sourceToTarget(Source source);
- @ReverseMappingMethod
+ @InheritInverseConfiguration
Source targetToSource(Target target);
Map intIntToNumberNumberMap(Map source);
diff --git a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapper.java
index d076407fd..5e02fdd14 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapper.java
@@ -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 carsToCarDtos(List cars);
- @ReverseMappingMethod
+ @InheritInverseConfiguration
List carDtosToCars(List carDtos);
PersonDto personToPersonDto(Person person);
- @ReverseMappingMethod
+ @InheritInverseConfiguration
Person personDtoToPerson(PersonDto personDto);
List personsToPersonDtos(List persons);
- @ReverseMappingMethod
+ @InheritInverseConfiguration
List personDtosToPersons(List personDtos);
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/SourceTargetMapper.java
index b7683b2bb..7e47a95fd 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/conversion/SourceTargetMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/SourceTargetMapper.java
@@ -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);
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java
index fd65fa48a..d4db8bfd7 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java
@@ -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 stringListToDateList(List dates);
- @ReverseMappingMethod
+ @InheritInverseConfiguration
List dateListToStringList(List strings);
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java
index 8fcccf99d..ef0e56365 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java
@@ -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);
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceTargetMapper.java
index 591b62f45..86fbc7569 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceTargetMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceTargetMapper.java
@@ -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);
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java
index 40550b2ef..4fcb2a47a 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java
@@ -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);
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/ReverseMappingMethodTest.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java
similarity index 74%
rename from processor/src/test/java/org/mapstruct/ap/test/reverse/ReverseMappingMethodTest.java
rename to processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java
index 8307f5eb5..67d721368 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/reverse/ReverseMappingMethodTest.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java
@@ -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() {
}
-
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapper.java
index aa1e1c390..a71b82dcb 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapper.java
@@ -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 )
diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbigious1.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbiguous1.java
similarity index 88%
rename from processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbigious1.java
rename to processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbiguous1.java
index 8365ec116..d8e5d5f4c 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbigious1.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbiguous1.java
@@ -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 )
diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbigious2.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbiguous2.java
similarity index 88%
rename from processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbigious2.java
rename to processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbiguous2.java
index dc297f23c..599122629 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbigious2.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbiguous2.java
@@ -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 )
diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbigious3.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbiguous3.java
similarity index 88%
rename from processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbigious3.java
rename to processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbiguous3.java
index 4643603f1..ca4ed42e7 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbigious3.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperAmbiguous3.java
@@ -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 )
diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperErroneouslyAnnotated.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperErroneouslyAnnotated.java
index b86f3cac8..9af307e08 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperErroneouslyAnnotated.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperErroneouslyAnnotated.java
@@ -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" ),
diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperNonMatchingName.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperNonMatchingName.java
index 88ccb7aa4..0303c4f94 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperNonMatchingName.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapperNonMatchingName.java
@@ -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 )