#1904 Do not include private methods when getting enclosed executable elements

This commit is contained in:
Filip Hrisafov 2019-09-21 10:24:25 +02:00
parent ad38786117
commit edcf78a34d

View File

@ -103,8 +103,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
@ -182,7 +182,7 @@ public class Executables {
List<ExecutableElement> methodsToAdd, TypeElement parentType) {
List<Accessor> safeToAdd = new ArrayList<>( methodsToAdd.size() );
for ( ExecutableElement toAdd : methodsToAdd ) {
if ( isNotObjectEquals( toAdd )
if ( isNotPrivate( toAdd ) && isNotObjectEquals( toAdd )
&& wasNotYetOverridden( elementUtils, alreadyCollected, toAdd, parentType ) ) {
safeToAdd.add( new ExecutableElementAccessor( toAdd ) );
}
@ -217,6 +217,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