@Test public void testGetPropertyGetterMethod() throws Exception { Method method = TestReflect.class.getMethod("getS"); Assert.assertEquals(method, getPropertyGetterMethod(TestReflect.class, "s")); method = TestReflect.class.getMethod("isB"); Assert.assertEquals(method, getPropertyGetterMethod(TestReflect.class, "b")); boolean error = false; try { getPropertyGetterMethod(TestReflect.class, "xxx"); } catch (Exception e) { error = true; } Assert.assertTrue(error); }
public static Method getPropertyGetterMethod(Class clazz, String property) { String methodName = "get" + property.substring(0, 1).toUpperCase() + property.substring(1); Method method; try { method = clazz.getMethod(methodName); } catch (NoSuchMethodException e) { try { methodName = "is" + property.substring(0, 1).toUpperCase() + property.substring(1); method = clazz.getMethod(methodName); } catch (NoSuchMethodException e1) { throw new SofaRpcRuntimeException("No getter method for " + clazz.getName() + "#" + property, e); } } return method; }
ReflectUtils { public static Method getPropertyGetterMethod(Class clazz, String property) { String methodName = "get" + property.substring(0, 1).toUpperCase() + property.substring(1); Method method; try { method = clazz.getMethod(methodName); } catch (NoSuchMethodException e) { try { methodName = "is" + property.substring(0, 1).toUpperCase() + property.substring(1); method = clazz.getMethod(methodName); } catch (NoSuchMethodException e1) { throw new SofaRpcRuntimeException("No getter method for " + clazz.getName() + "#" + property, e); } } return method; } }
ReflectUtils { public static Method getPropertyGetterMethod(Class clazz, String property) { String methodName = "get" + property.substring(0, 1).toUpperCase() + property.substring(1); Method method; try { method = clazz.getMethod(methodName); } catch (NoSuchMethodException e) { try { methodName = "is" + property.substring(0, 1).toUpperCase() + property.substring(1); method = clazz.getMethod(methodName); } catch (NoSuchMethodException e1) { throw new SofaRpcRuntimeException("No getter method for " + clazz.getName() + "#" + property, e); } } return method; }  }
ReflectUtils { public static Method getPropertyGetterMethod(Class clazz, String property) { String methodName = "get" + property.substring(0, 1).toUpperCase() + property.substring(1); Method method; try { method = clazz.getMethod(methodName); } catch (NoSuchMethodException e) { try { methodName = "is" + property.substring(0, 1).toUpperCase() + property.substring(1); method = clazz.getMethod(methodName); } catch (NoSuchMethodException e1) { throw new SofaRpcRuntimeException("No getter method for " + clazz.getName() + "#" + property, e); } } return method; }  static boolean isPrimitives(Class<?> clazz); static String getCodeBase(Class<?> cls); static Method getMethod(String clazzName, String methodName, String[] argsType); static Method getMethod(Class clazz, String methodName, Class... argsType); static Method getPropertySetterMethod(Class clazz, String property, Class propertyClazz); static Method getPropertyGetterMethod(Class clazz, String property); }
ReflectUtils { public static Method getPropertyGetterMethod(Class clazz, String property) { String methodName = "get" + property.substring(0, 1).toUpperCase() + property.substring(1); Method method; try { method = clazz.getMethod(methodName); } catch (NoSuchMethodException e) { try { methodName = "is" + property.substring(0, 1).toUpperCase() + property.substring(1); method = clazz.getMethod(methodName); } catch (NoSuchMethodException e1) { throw new SofaRpcRuntimeException("No getter method for " + clazz.getName() + "#" + property, e); } } return method; }  static boolean isPrimitives(Class<?> clazz); static String getCodeBase(Class<?> cls); static Method getMethod(String clazzName, String methodName, String[] argsType); static Method getMethod(Class clazz, String methodName, Class... argsType); static Method getPropertySetterMethod(Class clazz, String property, Class propertyClazz); static Method getPropertyGetterMethod(Class clazz, String property);  }