mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#1904 Do not include private methods when getting enclosed executable elements
This commit is contained in:
parent
e92e3b45c6
commit
fcdf852a17
@ -85,8 +85,8 @@ public class Executables {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds all executable elements within the given type element, including executable elements defined in super
|
* 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
|
* classes and implemented interfaces. Methods defined in {@link java.lang.Object},
|
||||||
* implementations of {@link java.lang.Object#equals(Object)}.
|
* implementations of {@link java.lang.Object#equals(Object)} and private methods are ignored
|
||||||
*
|
*
|
||||||
* @param elementUtils element helper
|
* @param elementUtils element helper
|
||||||
* @param element the element to inspect
|
* @param element the element to inspect
|
||||||
@ -143,7 +143,7 @@ public class Executables {
|
|||||||
List<ExecutableElement> methodsToAdd, TypeElement parentType) {
|
List<ExecutableElement> methodsToAdd, TypeElement parentType) {
|
||||||
List<ExecutableElement> safeToAdd = new ArrayList<>( methodsToAdd.size() );
|
List<ExecutableElement> safeToAdd = new ArrayList<>( methodsToAdd.size() );
|
||||||
for ( ExecutableElement toAdd : methodsToAdd ) {
|
for ( ExecutableElement toAdd : methodsToAdd ) {
|
||||||
if ( isNotObjectEquals( toAdd )
|
if ( isNotPrivate( toAdd ) && isNotObjectEquals( toAdd )
|
||||||
&& wasNotYetOverridden( elementUtils, alreadyCollected, toAdd, parentType ) ) {
|
&& wasNotYetOverridden( elementUtils, alreadyCollected, toAdd, parentType ) ) {
|
||||||
safeToAdd.add( toAdd );
|
safeToAdd.add( toAdd );
|
||||||
}
|
}
|
||||||
@ -168,6 +168,15 @@ public class Executables {
|
|||||||
return true;
|
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 elementUtils the elementUtils
|
||||||
* @param alreadyCollected the list of already collected methods of one type hierarchy (order is from sub-types to
|
* @param alreadyCollected the list of already collected methods of one type hierarchy (order is from sub-types to
|
||||||
|
Loading…
x
Reference in New Issue
Block a user