/** * Find the first public class in the methods declaring class hierarchy that declares this method. * Sometimes the reflective method discovery logic finds a suitable method that can easily be * called via reflection but cannot be called from generated code when compiling the expression * because of visibility restrictions. For example if a non-public class overrides toString(), * this helper method will walk up the type hierarchy to find the first public type that declares * the method (if there is one!). For toString() it may walk as far as Object. */ @Nullable public Class<?> getPublicDeclaringClass() { if (!this.computedPublicDeclaringClass) { this.publicDeclaringClass = discoverPublicDeclaringClass(this.originalMethod, this.originalMethod.getDeclaringClass()); this.computedPublicDeclaringClass = true; } return this.publicDeclaringClass; }
@Nullable private Class<?> discoverPublicDeclaringClass(Method method, Class<?> clazz) { if (Modifier.isPublic(clazz.getModifiers())) { try { clazz.getDeclaredMethod(method.getName(), method.getParameterTypes()); return clazz; } catch (NoSuchMethodException ex) { // Continue below... } } if (clazz.getSuperclass() != null) { return discoverPublicDeclaringClass(method, clazz.getSuperclass()); } return null; }
/** * Find the first public class in the methods declaring class hierarchy that declares this method. * Sometimes the reflective method discovery logic finds a suitable method that can easily be * called via reflection but cannot be called from generated code when compiling the expression * because of visibility restrictions. For example if a non-public class overrides toString(), * this helper method will walk up the type hierarchy to find the first public type that declares * the method (if there is one!). For toString() it may walk as far as Object. */ @Nullable public Class<?> getPublicDeclaringClass() { if (!this.computedPublicDeclaringClass) { this.publicDeclaringClass = discoverPublicDeclaringClass(this.originalMethod, this.originalMethod.getDeclaringClass()); this.computedPublicDeclaringClass = true; } return this.publicDeclaringClass; }
@Nullable private Class<?> discoverPublicDeclaringClass(Method method, Class<?> clazz) { if (Modifier.isPublic(clazz.getModifiers())) { try { clazz.getDeclaredMethod(method.getName(), method.getParameterTypes()); return clazz; } catch (NoSuchMethodException ex) { // Continue below... } } if (clazz.getSuperclass() != null) { return discoverPublicDeclaringClass(method, clazz.getSuperclass()); } return null; }
/** * Find the first public class in the methods declaring class hierarchy that declares this method. * Sometimes the reflective method discovery logic finds a suitable method that can easily be * called via reflection but cannot be called from generated code when compiling the expression * because of visibility restrictions. For example if a non-public class overrides toString(), * this helper method will walk up the type hierarchy to find the first public type that declares * the method (if there is one!). For toString() it may walk as far as Object. */ @Nullable public Class<?> getPublicDeclaringClass() { if (!this.computedPublicDeclaringClass) { this.publicDeclaringClass = discoverPublicDeclaringClass(this.method, this.method.getDeclaringClass()); this.computedPublicDeclaringClass = true; } return this.publicDeclaringClass; }
@Nullable private Class<?> discoverPublicDeclaringClass(Method method, Class<?> clazz) { if (Modifier.isPublic(clazz.getModifiers())) { try { clazz.getDeclaredMethod(method.getName(), method.getParameterTypes()); return clazz; } catch (NoSuchMethodException ex) { // Continue below... } } if (clazz.getSuperclass() != null) { return discoverPublicDeclaringClass(method, clazz.getSuperclass()); } return null; }