From 84bf019fdfbf115ea03d4186f86989eb7072c043 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 28 Apr 2018 09:10:56 +0200 Subject: [PATCH] More detailed check for adder in builde --- .../ap/spi/DefaultAccessorNamingStrategy.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index 72b910d1e..a5ee1a275 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -102,11 +102,24 @@ public class DefaultAccessorNamingStrategy implements AccessorNamingStrategy { protected boolean isBuilderSetter(ExecutableElement method) { return method.getParameters().size() == 1 && !JAVA_JAVAX_PACKAGE.matcher( method.getEnclosingElement().asType().toString() ).matches() && - !isAdderMethod( method ) && + !isAdderWithUpperCase4thCharacter( method ) && //TODO The Types need to be compared with Types#isSameType(TypeMirror, TypeMirror) method.getReturnType().toString().equals( method.getEnclosingElement().asType().toString() ); } + /** + * Checks that the method is an adder with an upper case 4th character. The reason for this is that methods such + * as {@code address(String address)} are considered as setter and {@code addName(String name)} too. We need to + * make sure that {@code addName} is considered as an adder and {@code address} is considered as a setter. + * + * @param method the method that needs to be checked + * + * @return {@code true} if the method is an adder with an upper case 4h character, {@code false} otherwise + */ + private boolean isAdderWithUpperCase4thCharacter(ExecutableElement method) { + return isAdderMethod( method ) && Character.isUpperCase( method.getSimpleName().toString().charAt( 3 ) ); + } + /** * Returns {@code true} when the {@link ExecutableElement} is an adder method. An adder method starts with 'add'. * The remainder of the name is supposed to reflect the singular property name (as opposed to plural) of