From a1cdd11bd5b015d3edb9762c4e8c5636e3f85d3c Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Fri, 6 Jun 2014 20:10:34 +0200 Subject: [PATCH] #220 Avoiding negated method name --- .../java/org/mapstruct/ap/model/common/Type.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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 f8c8e5027..63783b600 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 @@ -165,7 +165,7 @@ public class Type extends ModelElement implements Comparable { * implementation type is {@code HashSet}. * * @return The implementation type to be instantiated in case this type is an interface iterable, collection or map - * type, {@code null} otherwise. + * type, {@code null} otherwise. */ public Type getImplementationType() { return implementationType; @@ -302,7 +302,8 @@ public class Type extends ModelElement implements Comparable { // a getter could substitute the setter in that case and act as setter. // (assuming it is initialized) for ( ExecutableElement getterMethod : getterMethods ) { - if ( hasNoSetterMethod( getterMethod, setterMethods ) && isCollectionOrMap( getterMethod ) ) { + if ( isCollectionOrMap( getterMethod ) && + !correspondingSetterMethodExists( getterMethod, setterMethods ) ) { result.add( getterMethod ); } } @@ -312,15 +313,18 @@ public class Type extends ModelElement implements Comparable { return alternativeTargetAccessors; } - private boolean hasNoSetterMethod(ExecutableElement getterMethod, List setterMethods) { + private boolean correspondingSetterMethodExists(ExecutableElement getterMethod, + List setterMethods) { String getterPropertyName = Executables.getPropertyName( getterMethod ); + for ( ExecutableElement setterMethod : setterMethods ) { String setterPropertyName = Executables.getPropertyName( setterMethod ); if ( getterPropertyName.equals( setterPropertyName ) ) { - return false; + return true; } } - return true; + + return false; } private boolean isCollectionOrMap(ExecutableElement getterMethod) {