From fb6c4dbfbde0fff6b7b56d1c531cdd74fffd7bf0 Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Thu, 26 Mar 2015 20:39:45 +0100 Subject: [PATCH] #517 make order of target properties in generated code and in messages stable --- .../mapstruct/ap/model/BeanMappingMethod.java | 3 ++- .../java/org/mapstruct/ap/model/common/Type.java | 3 +-- .../inheritfromconfig/InheritFromConfigTest.java | 2 +- .../SeveralSourceParametersTest.java | 11 ++++++----- .../test/template/InheritConfigurationTest.java | 16 ++++++++-------- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java index 159db6986..0ce5e1275 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java @@ -26,6 +26,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -92,7 +93,7 @@ public class BeanMappingMethod extends MappingMethod { CollectionMappingStrategyPrism cms = sourceMethod.getMapperConfiguration().getCollectionMappingStrategy(); Map accessors = method.getResultType().getPropertyWriteAccessors( cms ); this.targetProperties = accessors.keySet(); - this.unprocessedTargetProperties = new HashMap( accessors ); + this.unprocessedTargetProperties = new LinkedHashMap( accessors ); for ( Parameter sourceParameter : method.getSourceParameters() ) { unprocessedSourceParameters.add( sourceParameter ); } diff --git a/processor/src/main/java/org/mapstruct/ap/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/model/common/Type.java index 98602ef46..6419df1e4 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/model/common/Type.java @@ -21,7 +21,6 @@ package org.mapstruct.ap.model.common; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -353,7 +352,7 @@ public class Type extends ModelElement implements Comparable { candidates.addAll( getSetters() ); candidates.addAll( getAlternativeTargetAccessors() ); - Map result = new HashMap(); + Map result = new LinkedHashMap(); for ( ExecutableElement candidate : candidates ) { String targetPropertyName = Executables.getPropertyName( candidate ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java index b47de959c..ed5135120 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java @@ -178,7 +178,7 @@ public class InheritFromConfigTest { @Diagnostic(type = Erroneous1Mapper.class, kind = Kind.WARNING, line = 36, - messageRegExp = "Unmapped target properties: \"auditTrail, primaryKey\"\\."), + messageRegExp = "Unmapped target properties: \"primaryKey, auditTrail\"\\."), @Diagnostic(type = Erroneous1Mapper.class, kind = Kind.ERROR, line = 42, diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java b/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java index 5c71c20b5..85049e6fa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.test.severalsources; -import static org.fest.assertions.Assertions.assertThat; - import javax.lang.model.SourceVersion; import javax.tools.Diagnostic.Kind; @@ -33,6 +31,8 @@ import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutco import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.fest.assertions.Assertions.assertThat; + /** * Test for propagation of attribute without setter in source and getter in * target. @@ -127,12 +127,13 @@ public class SeveralSourceParametersTest { @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, line = 29, - messageRegExp = "Several possible source properties for target property \"zipCode\".") , + messageRegExp = "Several possible source properties for target property \"zipCode\".", + javaVersions = { SourceVersion.RELEASE_6 } ), @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, line = 29, - messageRegExp = "Several possible source properties for target property \"street\".", - javaVersions = { SourceVersion.RELEASE_6 } ) + messageRegExp = "Several possible source properties for target property \"street\"."), + }) public void shouldFailToGenerateMappingsForAmbigiousSourceProperty() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java b/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java index 883d66115..6cacbeca8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java @@ -136,8 +136,8 @@ public class InheritConfigurationTest { @Diagnostic(type = SourceTargetMapperAmbiguous1.class, kind = Kind.WARNING, line = 55, - messageRegExp = "Unmapped target properties: \"stringPropY, nestedResultProp, integerPropY, " - + "constantProp, expressionProp\"") + messageRegExp = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " + + "expressionProp, nestedResultProp\"") } ) public void shouldRaiseAmbiguousReverseMethodError() { @@ -156,8 +156,8 @@ public class InheritConfigurationTest { @Diagnostic(type = SourceTargetMapperAmbiguous2.class, kind = Kind.WARNING, line = 55, - messageRegExp = "Unmapped target properties: \"stringPropY, nestedResultProp, integerPropY, " - + "constantProp, expressionProp\"") + messageRegExp = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " + + "expressionProp, nestedResultProp\"") } ) public void shouldRaiseAmbiguousReverseMethodErrorWrongName() { @@ -176,8 +176,8 @@ public class InheritConfigurationTest { @Diagnostic(type = SourceTargetMapperAmbiguous3.class, kind = Kind.WARNING, line = 55, - messageRegExp = "Unmapped target properties: \"stringPropY, nestedResultProp, integerPropY, " - + "constantProp, expressionProp\"") } + messageRegExp = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " + + "expressionProp, nestedResultProp\"") } ) public void shouldRaiseAmbiguousReverseMethodErrorDuplicatedName() { } @@ -195,8 +195,8 @@ public class InheritConfigurationTest { @Diagnostic(type = SourceTargetMapperNonMatchingName.class, kind = Kind.WARNING, line = 46, - messageRegExp = "Unmapped target properties: \"stringPropY, nestedResultProp, integerPropY, " - + "constantProp, expressionProp\"") + messageRegExp = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " + + "expressionProp, nestedResultProp\"") } ) public void shouldAdviseOnSpecifyingCorrectName() {