This commit is contained in:
Gunnar Morling 2014-10-14 22:03:07 +02:00
parent 32eeceb0cf
commit 4d408d5560
10 changed files with 243 additions and 240 deletions

View File

@ -25,7 +25,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import javax.annotation.processing.Messager; import javax.annotation.processing.Messager;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
@ -312,7 +311,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
else if ( method.isEnumMapping() ) { else if ( method.isEnumMapping() ) {
EnumMappingMethod.Builder builder = new EnumMappingMethod.Builder(); EnumMappingMethod.Builder builder = new EnumMappingMethod.Builder();
mergeWithReverseMappings( reverseMappingMethod, method); mergeWithReverseMappings( reverseMappingMethod, method );
if ( method.getMappings().isEmpty() ) { if ( method.getMappings().isEmpty() ) {
if ( reverseMappingMethod != null && !reverseMappingMethod.getMappings().isEmpty() ) { if ( reverseMappingMethod != null && !reverseMappingMethod.getMappings().isEmpty() ) {
method.setMappings( reverse( reverseMappingMethod.getMappings() ) ); method.setMappings( reverse( reverseMappingMethod.getMappings() ) );
@ -331,7 +330,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
else { else {
BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder(); BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder();
mergeWithReverseMappings( reverseMappingMethod, method); mergeWithReverseMappings( reverseMappingMethod, method );
BeanMappingMethod beanMappingMethod = builder BeanMappingMethod beanMappingMethod = builder
.mappingContext( mappingContext ) .mappingContext( mappingContext )
.souceMethod( method ) .souceMethod( method )
@ -386,7 +385,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
return reversed; return reversed;
} }
private void mergeWithReverseMappings( SourceMethod reverseMappingMethod, SourceMethod method ) { private void mergeWithReverseMappings(SourceMethod reverseMappingMethod, SourceMethod method) {
Map<String, List<Mapping>> newMappings = new HashMap<String, List<Mapping>>(); Map<String, List<Mapping>> newMappings = new HashMap<String, List<Mapping>>();
if ( reverseMappingMethod != null && !reverseMappingMethod.getMappings().isEmpty() ) { if ( reverseMappingMethod != null && !reverseMappingMethod.getMappings().isEmpty() ) {
// define all the base mappings based on its forward counterpart // define all the base mappings based on its forward counterpart
@ -406,12 +405,12 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
} }
} }
private SourceMethod getReverseMappingMethod(List<SourceMethod> rawMethods, SourceMethod method) { private SourceMethod getReverseMappingMethod(List<SourceMethod> rawMethods, SourceMethod method) {
SourceMethod result = null; SourceMethod result = null;
InheritInverseConfigurationPrism reversePrism = InheritInverseConfigurationPrism.getInstanceOn(
method.getExecutable()
);
InheritInverseConfigurationPrism reversePrism = InheritInverseConfigurationPrism.getInstanceOn( method.getExecutable() );
if ( reversePrism != null ) { if ( reversePrism != null ) {
// method is configured as being reverse method, collect candidates // method is configured as being reverse method, collect candidates
@ -445,7 +444,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
} }
} }
if ( nameFilteredcandidates.size() == 1 ) { if ( nameFilteredcandidates.size() == 1 ) {
result = nameFilteredcandidates.get( 0 ); result = nameFilteredcandidates.get( 0 );
} }
else if ( nameFilteredcandidates.size() > 1 ) { else if ( nameFilteredcandidates.size() > 1 ) {
@ -458,74 +457,93 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
} }
if ( result != null ) { if ( result != null ) {
reportErrorIfForwardMethodHasInheritInverseConfigurationAnnotation( result, method, reversePrism ); reportErrorIfInverseMethodHasInheritAnnotation( result, method, reversePrism );
} }
} }
return result; return result;
} }
private void reportErrorIfForwardMethodHasInheritInverseConfigurationAnnotation( SourceMethod candidate, private void reportErrorIfInverseMethodHasInheritAnnotation(SourceMethod candidate,
SourceMethod method, InheritInverseConfigurationPrism reversePrism ) { SourceMethod method,
InheritInverseConfigurationPrism reversePrism) {
InheritInverseConfigurationPrism candidatePrism = InheritInverseConfigurationPrism.getInstanceOn(
candidate.getExecutable()
);
InheritInverseConfigurationPrism candidatePrism = InheritInverseConfigurationPrism.getInstanceOn( candidate.getExecutable() );
if ( candidatePrism != null ) { if ( candidatePrism != null ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage(
String.format( "Resolved inverse mapping method %s() should not carry the " Diagnostic.Kind.ERROR,
+ "@InheritInverseConfiguration annotation itself.", String.format(
candidate.getName() "Resolved inverse mapping method %s() should not carry the "
), + "@InheritInverseConfiguration annotation itself.",
method.getExecutable(), candidate.getName()
reversePrism.mirror ); ),
method.getExecutable(),
reversePrism.mirror
);
} }
} }
private void reportErrorWhenAmbigousReverseMapping( List<SourceMethod> candidates, SourceMethod method, private void reportErrorWhenAmbigousReverseMapping(List<SourceMethod> candidates, SourceMethod method,
InheritInverseConfigurationPrism reversePrism ) { InheritInverseConfigurationPrism reversePrism) {
List<String> candidateNames = new ArrayList<String>(); List<String> candidateNames = new ArrayList<String>();
for (SourceMethod candidate : candidates ) { for ( SourceMethod candidate : candidates ) {
candidateNames.add( candidate.getName() ); candidateNames.add( candidate.getName() );
} }
String name = reversePrism.name(); String name = reversePrism.name();
if ( name.isEmpty() ) { if ( name.isEmpty() ) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage(
String.format( "Several matching inverse methods exist: %s(). Specify a name explicitly.", Diagnostic.Kind.ERROR,
Strings.join( candidateNames, "(), " ) String.format(
), "Several matching inverse methods exist: %s(). Specify a name explicitly.",
method.getExecutable(), Strings.join( candidateNames, "(), " )
reversePrism.mirror ); ),
method.getExecutable(),
reversePrism.mirror
);
} }
else { else {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage(
String.format( "None of the candidates %s() matches given name: \"%s\".", Diagnostic.Kind.ERROR,
Strings.join( candidateNames, "(), " ), name String.format(
), "None of the candidates %s() matches given name: \"%s\".",
method.getExecutable(), Strings.join( candidateNames, "(), " ), name
reversePrism.mirror ); ),
method.getExecutable(),
reversePrism.mirror
);
} }
} }
private void reportErrorWhenSeveralNamesMatch(List<SourceMethod> candidates, SourceMethod method, private void reportErrorWhenSeveralNamesMatch(List<SourceMethod> candidates, SourceMethod method,
InheritInverseConfigurationPrism reversePrism ) { InheritInverseConfigurationPrism reversePrism) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage(
String.format( "Given name \"%s\" matches several candidate methods: %s().", Diagnostic.Kind.ERROR,
reversePrism.name(), Strings.join( candidates, "(), " ) String.format(
), "Given name \"%s\" matches several candidate methods: %s().",
method.getExecutable(), reversePrism.name(), Strings.join( candidates, "(), " )
reversePrism.mirror ); ),
method.getExecutable(),
reversePrism.mirror
);
} }
private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method, private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method,
InheritInverseConfigurationPrism reversePrism ) { InheritInverseConfigurationPrism reversePrism) {
messager.printMessage( Diagnostic.Kind.ERROR, messager.printMessage(
String.format( "Given name \"%s\" does not match the only candidate. Did you mean: \"%s\".", Diagnostic.Kind.ERROR,
reversePrism.name(), onlyCandidate.getName() String.format(
), "Given name \"%s\" does not match the only candidate. Did you mean: \"%s\".",
method.getExecutable(), reversePrism.name(), onlyCandidate.getName()
reversePrism.mirror ); ),
method.getExecutable(),
reversePrism.mirror
);
} }
} }

View File

@ -18,8 +18,6 @@
*/ */
package org.mapstruct.ap.test.reverse; package org.mapstruct.ap.test.reverse;
import static org.fest.assertions.Assertions.assertThat;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import org.junit.Test; import org.junit.Test;
@ -31,17 +29,18 @@ import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.fest.assertions.Assertions.assertThat;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*
*/ */
@IssueKey( "252" ) @IssueKey("252")
@WithClasses( { Source.class, Target.class } ) @WithClasses({ Source.class, Target.class })
@RunWith( AnnotationProcessorTestRunner.class ) @RunWith(AnnotationProcessorTestRunner.class)
public class InheritInverseConfigurationTest { public class InheritInverseConfigurationTest {
@Test @Test
@WithClasses( { SourceTargetMapper.class } ) @WithClasses({ SourceTargetMapper.class })
public void shouldInheritInverseConfigurationMultipleCandidates() { public void shouldInheritInverseConfigurationMultipleCandidates() {
Source source = new Source(); Source source = new Source();
@ -64,92 +63,92 @@ public class InheritInverseConfigurationTest {
} }
@Test @Test
@WithClasses( { SourceTargetMapperAmbiguous1.class } ) @WithClasses({ SourceTargetMapperAmbiguous1.class })
@ExpectedCompilationOutcome( @ExpectedCompilationOutcome(
value = CompilationResult.FAILED, value = CompilationResult.FAILED,
diagnostics = { diagnostics = {
@Diagnostic( type = SourceTargetMapperAmbiguous1.class, @Diagnostic(type = SourceTargetMapperAmbiguous1.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 51, line = 49,
messageRegExp = "Several matching inverse methods exist: forward\\(\\), " messageRegExp = "Several matching inverse methods exist: forward\\(\\), "
+ "forwardNotToReverse\\(\\). Specify a name explicitly." ), + "forwardNotToReverse\\(\\). Specify a name explicitly."),
@Diagnostic( type = SourceTargetMapperAmbiguous1.class, @Diagnostic(type = SourceTargetMapperAmbiguous1.class,
kind = Kind.WARNING, kind = Kind.WARNING,
line = 56, line = 54,
messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"" ) messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"")
} }
) )
public void shouldRaiseAmbiguousReverseMethodError() { public void shouldRaiseAmbiguousReverseMethodError() {
} }
@Test @Test
@WithClasses( { SourceTargetMapperAmbiguous2.class } ) @WithClasses({ SourceTargetMapperAmbiguous2.class })
@ExpectedCompilationOutcome( @ExpectedCompilationOutcome(
value = CompilationResult.FAILED, value = CompilationResult.FAILED,
diagnostics = { diagnostics = {
@Diagnostic( type = SourceTargetMapperAmbiguous2.class, @Diagnostic(type = SourceTargetMapperAmbiguous2.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 51, line = 49,
messageRegExp = "None of the candidates forward\\(\\), forwardNotToReverse\\(\\) matches given " messageRegExp = "None of the candidates forward\\(\\), forwardNotToReverse\\(\\) matches given "
+ "name: \"blah\"." ), + "name: \"blah\"."),
@Diagnostic( type = SourceTargetMapperAmbiguous2.class, @Diagnostic(type = SourceTargetMapperAmbiguous2.class,
kind = Kind.WARNING, kind = Kind.WARNING,
line = 56, line = 54,
messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"" ) messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"")
} }
) )
public void shouldRaiseAmbiguousReverseMethodErrorWrongName() { public void shouldRaiseAmbiguousReverseMethodErrorWrongName() {
} }
@Test @Test
@WithClasses( { SourceTargetMapperAmbiguous3.class } ) @WithClasses({ SourceTargetMapperAmbiguous3.class })
@ExpectedCompilationOutcome( @ExpectedCompilationOutcome(
value = CompilationResult.FAILED, value = CompilationResult.FAILED,
diagnostics = { diagnostics = {
@Diagnostic( type = SourceTargetMapperAmbiguous3.class, @Diagnostic(type = SourceTargetMapperAmbiguous3.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 52, line = 50,
messageRegExp = "Given name \"forward\" matches several candidate methods: .*forward.*\\(\\), " messageRegExp = "Given name \"forward\" matches several candidate methods: .*forward.*\\(\\), "
+ ".*forward.*\\(\\)" ), + ".*forward.*\\(\\)"),
@Diagnostic( type = SourceTargetMapperAmbiguous3.class, @Diagnostic(type = SourceTargetMapperAmbiguous3.class,
kind = Kind.WARNING, kind = Kind.WARNING,
line = 57, line = 55,
messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"" ) messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"")
} }
) )
public void shouldRaiseAmbiguousReverseMethodErrorDuplicatedName() { public void shouldRaiseAmbiguousReverseMethodErrorDuplicatedName() {
} }
@Test @Test
@WithClasses( { SourceTargetMapperErroneouslyAnnotated.class } ) @WithClasses({ SourceTargetMapperErroneouslyAnnotated.class })
@ExpectedCompilationOutcome( @ExpectedCompilationOutcome(
value = CompilationResult.FAILED, value = CompilationResult.FAILED,
diagnostics = { diagnostics = {
@Diagnostic( type = SourceTargetMapperErroneouslyAnnotated.class, @Diagnostic(type = SourceTargetMapperErroneouslyAnnotated.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 51, line = 49,
messageRegExp = "Resolved inverse mapping method reverse\\(\\) should not carry the " messageRegExp = "Resolved inverse mapping method reverse\\(\\) should not carry the "
+ "@InheritInverseConfiguration annotation itself." ) + "@InheritInverseConfiguration annotation itself.")
} }
) )
public void shouldUseWronglyAnnotatedError() { public void shouldUseWronglyAnnotatedError() {
} }
@Test @Test
@WithClasses( { SourceTargetMapperNonMatchingName.class } ) @WithClasses({ SourceTargetMapperNonMatchingName.class })
@ExpectedCompilationOutcome( @ExpectedCompilationOutcome(
value = CompilationResult.FAILED, value = CompilationResult.FAILED,
diagnostics = { diagnostics = {
@Diagnostic( type = SourceTargetMapperNonMatchingName.class, @Diagnostic(type = SourceTargetMapperNonMatchingName.class,
kind = Kind.ERROR, kind = Kind.ERROR,
line = 44, line = 42,
messageRegExp = "Given name \"blah\" does not match the only candidate. Did you mean: " messageRegExp = "Given name \"blah\" does not match the only candidate. Did you mean: "
+ "\"forward\"." ), + "\"forward\"."),
@Diagnostic( type = SourceTargetMapperNonMatchingName.class, @Diagnostic(type = SourceTargetMapperNonMatchingName.class,
kind = Kind.WARNING, kind = Kind.WARNING,
line = 49, line = 47,
messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"" ) messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"")
} }
) )
public void shouldAdviseOnSpecifyingCorrectName() { public void shouldAdviseOnSpecifyingCorrectName() {
} }

View File

@ -19,7 +19,6 @@
package org.mapstruct.ap.test.reverse; package org.mapstruct.ap.test.reverse;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class Source { public class Source {
@ -36,7 +35,7 @@ public class Source {
return stringPropX; return stringPropX;
} }
public void setStringPropX( String stringPropX ) { public void setStringPropX(String stringPropX) {
this.stringPropX = stringPropX; this.stringPropX = stringPropX;
} }
@ -44,7 +43,7 @@ public class Source {
return integerPropX; return integerPropX;
} }
public void setIntegerPropX( Integer integerPropX ) { public void setIntegerPropX(Integer integerPropX) {
this.integerPropX = integerPropX; this.integerPropX = integerPropX;
} }
@ -52,7 +51,7 @@ public class Source {
return someConstantDownstream; return someConstantDownstream;
} }
public void setSomeConstantDownstream( String someConstantDownstream ) { public void setSomeConstantDownstream(String someConstantDownstream) {
this.someConstantDownstream = someConstantDownstream; this.someConstantDownstream = someConstantDownstream;
} }
@ -60,7 +59,7 @@ public class Source {
return propertyToIgnoreDownstream; return propertyToIgnoreDownstream;
} }
public void setPropertyToIgnoreDownstream( String propertyToIgnoreDownstream ) { public void setPropertyToIgnoreDownstream(String propertyToIgnoreDownstream) {
this.propertyToIgnoreDownstream = propertyToIgnoreDownstream; this.propertyToIgnoreDownstream = propertyToIgnoreDownstream;
} }

View File

@ -25,33 +25,31 @@ import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
@Mapper @Mapper
public interface SourceTargetMapper { public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
@Mappings( { @Mappings({
@Mapping( source = "stringPropX", target = "stringPropY" ), @Mapping(source = "stringPropX", target = "stringPropY"),
@Mapping( source = "integerPropX", target = "integerPropY" ), @Mapping(source = "integerPropX", target = "integerPropY"),
@Mapping( source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream" ) @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream")
} ) })
Target forward( Source source ); Target forward(Source source);
@Mappings( { @Mappings({
@Mapping( source = "stringPropX", target = "stringPropY" ), @Mapping(source = "stringPropX", target = "stringPropY"),
@Mapping( source = "integerPropX", target = "integerPropY" ), @Mapping(source = "integerPropX", target = "integerPropY"),
@Mapping( source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream" ) @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream")
} ) })
Target forwardNotToReverse( Source source ); Target forwardNotToReverse(Source source);
@InheritInverseConfiguration( name = "forward" ) @InheritInverseConfiguration(name = "forward")
@Mappings( { @Mappings({
@Mapping( target = "someConstantDownstream", constant = "test" ), @Mapping(target = "someConstantDownstream", constant = "test"),
@Mapping( source = "propertyToIgnoreDownstream", ignore = true ) @Mapping(source = "propertyToIgnoreDownstream", ignore = true)
} ) })
Source reverse( Target target ); Source reverse(Target target);
} }

View File

@ -18,40 +18,38 @@
*/ */
package org.mapstruct.ap.test.reverse; package org.mapstruct.ap.test.reverse;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.Mappings; import org.mapstruct.Mappings;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
@Mapper @Mapper
public interface SourceTargetMapperAmbiguous1 { public interface SourceTargetMapperAmbiguous1 {
SourceTargetMapperAmbiguous1 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbiguous1.class ); SourceTargetMapperAmbiguous1 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbiguous1.class );
@Mappings( { @Mappings({
@Mapping( source = "stringPropX", target = "stringPropY" ), @Mapping(source = "stringPropX", target = "stringPropY"),
@Mapping( source = "integerPropX", target = "integerPropY" ), @Mapping(source = "integerPropX", target = "integerPropY"),
@Mapping( source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream" ) @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream")
} ) })
Target forward( Source source ); Target forward(Source source);
@Mappings( { @Mappings({
@Mapping( source = "stringPropX", target = "stringPropY" ), @Mapping(source = "stringPropX", target = "stringPropY"),
@Mapping( source = "integerPropX", target = "integerPropY" ), @Mapping(source = "integerPropX", target = "integerPropY"),
@Mapping( source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream" ) @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream")
} ) })
Target forwardNotToReverse( Source source ); Target forwardNotToReverse(Source source);
@InheritInverseConfiguration @InheritInverseConfiguration
@Mappings( { @Mappings({
@Mapping( target = "someConstantDownstream", constant = "test" ), @Mapping(target = "someConstantDownstream", constant = "test"),
@Mapping( source = "propertyToIgnoreDownstream", ignore = true ) @Mapping(source = "propertyToIgnoreDownstream", ignore = true)
} ) })
Source reverse( Target target ); Source reverse(Target target);
} }

View File

@ -25,33 +25,31 @@ import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
@Mapper @Mapper
public interface SourceTargetMapperAmbiguous2 { public interface SourceTargetMapperAmbiguous2 {
SourceTargetMapperAmbiguous2 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbiguous2.class ); SourceTargetMapperAmbiguous2 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbiguous2.class );
@Mappings( { @Mappings({
@Mapping( source = "stringPropX", target = "stringPropY" ), @Mapping(source = "stringPropX", target = "stringPropY"),
@Mapping( source = "integerPropX", target = "integerPropY" ), @Mapping(source = "integerPropX", target = "integerPropY"),
@Mapping( source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream" ) @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream")
} ) })
Target forward( Source source ); Target forward(Source source);
@Mappings( { @Mappings({
@Mapping( source = "stringPropX", target = "stringPropY" ), @Mapping(source = "stringPropX", target = "stringPropY"),
@Mapping( source = "integerPropX", target = "integerPropY" ), @Mapping(source = "integerPropX", target = "integerPropY"),
@Mapping( source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream" ) @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream")
} ) })
Target forwardNotToReverse( Source source ); Target forwardNotToReverse(Source source);
@InheritInverseConfiguration( name = "blah" ) @InheritInverseConfiguration(name = "blah")
@Mappings( { @Mappings({
@Mapping( target = "someConstantDownstream", constant = "test" ), @Mapping(target = "someConstantDownstream", constant = "test"),
@Mapping( source = "propertyToIgnoreDownstream", ignore = true ) @Mapping(source = "propertyToIgnoreDownstream", ignore = true)
} ) })
Source reverse( Target target ); Source reverse(Target target);
} }

View File

@ -26,33 +26,31 @@ import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
@Mapper @Mapper
public interface SourceTargetMapperAmbiguous3 { public interface SourceTargetMapperAmbiguous3 {
SourceTargetMapperAmbiguous3 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbiguous3.class ); SourceTargetMapperAmbiguous3 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbiguous3.class );
@Mappings( { @Mappings({
@Mapping( source = "stringPropX", target = "stringPropY" ), @Mapping(source = "stringPropX", target = "stringPropY"),
@Mapping( source = "integerPropX", target = "integerPropY" ), @Mapping(source = "integerPropX", target = "integerPropY"),
@Mapping( source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream" ) @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream")
} ) })
Target forward( Source source ); Target forward(Source source);
@Mappings( { @Mappings({
@Mapping( source = "stringPropX", target = "stringPropY" ), @Mapping(source = "stringPropX", target = "stringPropY"),
@Mapping( source = "integerPropX", target = "integerPropY" ), @Mapping(source = "integerPropX", target = "integerPropY"),
@Mapping( source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream" ) @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream")
} ) })
Target forward( Source source, @MappingTarget Target target ); Target forward(Source source, @MappingTarget Target target);
@InheritInverseConfiguration( name = "forward" ) @InheritInverseConfiguration(name = "forward")
@Mappings( { @Mappings({
@Mapping( target = "someConstantDownstream", constant = "test" ), @Mapping(target = "someConstantDownstream", constant = "test"),
@Mapping( source = "propertyToIgnoreDownstream", ignore = true ) @Mapping(source = "propertyToIgnoreDownstream", ignore = true)
} ) })
Source reverse( Target target ); Source reverse(Target target);
} }

View File

@ -25,34 +25,32 @@ import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
@Mapper @Mapper
public interface SourceTargetMapperErroneouslyAnnotated { public interface SourceTargetMapperErroneouslyAnnotated {
SourceTargetMapperErroneouslyAnnotated INSTANCE = Mappers.getMapper( SourceTargetMapperErroneouslyAnnotated.class ); SourceTargetMapperErroneouslyAnnotated INSTANCE = Mappers.getMapper( SourceTargetMapperErroneouslyAnnotated.class );
@Mappings( { @Mappings({
@Mapping( source = "stringPropX", target = "stringPropY" ), @Mapping(source = "stringPropX", target = "stringPropY"),
@Mapping( source = "integerPropX", target = "integerPropY" ), @Mapping(source = "integerPropX", target = "integerPropY"),
@Mapping( source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream" ) @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream")
} ) })
Target forward( Source source ); Target forward(Source source);
@InheritInverseConfiguration( name = "forward" ) @InheritInverseConfiguration(name = "forward")
@Mappings( { @Mappings({
@Mapping( target = "someConstantDownstream", constant = "test" ), @Mapping(target = "someConstantDownstream", constant = "test"),
@Mapping( source = "propertyToIgnoreDownstream", ignore = true ) @Mapping(source = "propertyToIgnoreDownstream", ignore = true)
} ) })
Source reverse( Target target ); Source reverse(Target target);
@InheritInverseConfiguration( name = "reverse" ) @InheritInverseConfiguration(name = "reverse")
@Mappings( { @Mappings({
@Mapping( source = "stringPropX", target = "stringPropY" ), @Mapping(source = "stringPropX", target = "stringPropY"),
@Mapping( source = "integerPropX", target = "integerPropY" ), @Mapping(source = "integerPropX", target = "integerPropY"),
@Mapping( source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream" ) @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream")
} ) })
Target forward2( Source source ); Target forward2(Source source);
} }

View File

@ -25,26 +25,24 @@ import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
@Mapper @Mapper
public interface SourceTargetMapperNonMatchingName { public interface SourceTargetMapperNonMatchingName {
SourceTargetMapperNonMatchingName INSTANCE = Mappers.getMapper( SourceTargetMapperNonMatchingName.class ); SourceTargetMapperNonMatchingName INSTANCE = Mappers.getMapper( SourceTargetMapperNonMatchingName.class );
@Mappings( { @Mappings({
@Mapping( source = "stringPropX", target = "stringPropY" ), @Mapping(source = "stringPropX", target = "stringPropY"),
@Mapping( source = "integerPropX", target = "integerPropY" ), @Mapping(source = "integerPropX", target = "integerPropY"),
@Mapping( source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream" ) @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream")
} ) })
Target forward( Source source ); Target forward(Source source);
@InheritInverseConfiguration( name = "blah" ) @InheritInverseConfiguration(name = "blah")
@Mappings( { @Mappings({
@Mapping( target = "someConstantDownstream", constant = "test" ), @Mapping(target = "someConstantDownstream", constant = "test"),
@Mapping( source = "propertyToIgnoreDownstream", ignore = true ) @Mapping(source = "propertyToIgnoreDownstream", ignore = true)
} ) })
Source reverse( Target target ); Source reverse(Target target);
} }

View File

@ -19,7 +19,6 @@
package org.mapstruct.ap.test.reverse; package org.mapstruct.ap.test.reverse;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class Target { public class Target {
@ -34,7 +33,7 @@ public class Target {
return stringPropY; return stringPropY;
} }
public void setStringPropY( String stringPropY ) { public void setStringPropY(String stringPropY) {
this.stringPropY = stringPropY; this.stringPropY = stringPropY;
} }
@ -42,7 +41,7 @@ public class Target {
return integerPropY; return integerPropY;
} }
public void setIntegerPropY( Integer integerPropY ) { public void setIntegerPropY(Integer integerPropY) {
this.integerPropY = integerPropY; this.integerPropY = integerPropY;
} }
@ -50,7 +49,7 @@ public class Target {
return propertyNotToIgnoreUpstream; return propertyNotToIgnoreUpstream;
} }
public void setPropertyNotToIgnoreUpstream( String propertyNotToIgnoreUpstream ) { public void setPropertyNotToIgnoreUpstream(String propertyNotToIgnoreUpstream) {
this.propertyNotToIgnoreUpstream = propertyNotToIgnoreUpstream; this.propertyNotToIgnoreUpstream = propertyNotToIgnoreUpstream;
} }