From fcdf852a172ad04c1dceb413c3f29a1d0273e49a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 21 Sep 2019 10:24:25 +0200 Subject: [PATCH] #1904 Do not include private methods when getting enclosed executable elements --- .../mapstruct/ap/internal/util/Executables.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java index 8c554bc1f..4fbae2bdb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java @@ -85,8 +85,8 @@ public class Executables { /** * Finds all executable elements within the given type element, including executable elements defined in super - * classes and implemented interfaces. Methods defined in {@link java.lang.Object} are ignored, as well as - * implementations of {@link java.lang.Object#equals(Object)}. + * classes and implemented interfaces. Methods defined in {@link java.lang.Object}, + * implementations of {@link java.lang.Object#equals(Object)} and private methods are ignored * * @param elementUtils element helper * @param element the element to inspect @@ -143,7 +143,7 @@ public class Executables { List methodsToAdd, TypeElement parentType) { List safeToAdd = new ArrayList<>( methodsToAdd.size() ); for ( ExecutableElement toAdd : methodsToAdd ) { - if ( isNotObjectEquals( toAdd ) + if ( isNotPrivate( toAdd ) && isNotObjectEquals( toAdd ) && wasNotYetOverridden( elementUtils, alreadyCollected, toAdd, parentType ) ) { safeToAdd.add( toAdd ); } @@ -168,6 +168,15 @@ public class Executables { return true; } + /** + * @param executable the executable to check + * + * @return {@code true}, iff the executable does not have a private modifier + */ + private static boolean isNotPrivate(ExecutableElement executable) { + return !executable.getModifiers().contains( Modifier.PRIVATE ); + } + /** * @param elementUtils the elementUtils * @param alreadyCollected the list of already collected methods of one type hierarchy (order is from sub-types to