Internal refactoring.

This commit is contained in:
Gary Gregory 2021-11-15 14:21:18 -05:00
parent 6bda5d18d2
commit 38533393ba
2 changed files with 15 additions and 6 deletions

View File

@ -107,7 +107,7 @@ public class FieldUtils {
final Field field = acls.getDeclaredField(fieldName);
// getDeclaredField checks for non-public scopes as well
// and it returns accurate results
if (!Modifier.isPublic(field.getModifiers())) {
if (!MemberUtils.isPublic(field)) {
if (!forceAccess) {
continue;
}

View File

@ -30,7 +30,7 @@ import org.apache.commons.lang3.ClassUtils;
*
* @since 2.5
*/
abstract class MemberUtils {
final class MemberUtils {
// TODO extract an interface to implement compareParameterSets(...)?
private static final int ACCESS_TEST = Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE;
@ -57,7 +57,7 @@ abstract class MemberUtils {
return false;
}
final Member m = (Member) obj;
if (!obj.isAccessible() && Modifier.isPublic(m.getModifiers()) && isPackageAccess(m.getDeclaringClass().getModifiers())) {
if (!obj.isAccessible() && isPublic(m) && isPackageAccess(m.getDeclaringClass().getModifiers())) {
try {
obj.setAccessible(true);
return true;
@ -77,9 +77,18 @@ abstract class MemberUtils {
return (modifiers & ACCESS_TEST) == 0;
}
/**
* Tests whether a {@link Member} is public.
* @param member Member to test
* @return {@code true} if {@code m} is public
*/
static boolean isPublic(final Member member) {
return member != null && Modifier.isPublic(member.getModifiers());
}
/**
* Tests whether a {@link Member} is static.
* @param member Member to check
* @param member Member to test
* @return {@code true} if {@code m} is static
*/
static boolean isStatic(final Member member) {
@ -88,11 +97,11 @@ abstract class MemberUtils {
/**
* Tests whether a {@link Member} is accessible.
* @param member Member to check
* @param member Member to test
* @return {@code true} if {@code m} is accessible
*/
static boolean isAccessible(final Member member) {
return member != null && Modifier.isPublic(member.getModifiers()) && !member.isSynthetic();
return member != null && isPublic(member) && !member.isSynthetic();
}
/**