Pace2Car commented on code in PR #27991:
URL: https://github.com/apache/shardingsphere/pull/27991#discussion_r1286925170


##########
infra/util/src/main/java/org/apache/shardingsphere/infra/util/reflection/ReflectionUtils.java:
##########
@@ -134,4 +137,36 @@ public static <T> T invokeMethod(final Method method, 
final Object target, final
         }
         return result;
     }
+    
+    /**
+     * Get field value by get method.
+     *
+     * @param target target
+     * @param fieldName field name
+     * @param <T> type of field value
+     * @return field value
+     */
+    public static <T> Optional<T> getFieldValueByGetMethod(final Object 
target, final String fieldName) {
+        String getterName = GETTER_PREFIX + 
CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, fieldName);
+        final Method method = findMethod(target.getClass(), getterName);
+        if (method != null) {
+            T value = invokeMethod(method, target);
+            return Optional.ofNullable(value);
+        }
+        
+        return Optional.empty();
+    }
+    
+    private static Method findMethod(final Class<?> clazz, final String 
methodName, final Class<?>... parameterTypes) {
+        try {
+            return clazz.getMethod(methodName, parameterTypes);
+        } catch (NoSuchMethodException e) {
+            // Try superclass if method not found in this class

Review Comment:
   Do not leave comments.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to