public static boolean isAccessorPresent(String prefix, String property, Class<?> bean) { try { bean.getMethod(prefix + capitalize(property)); return true; } catch (NoSuchMethodException ex) { return false; } }
public static Method getAccessor(String prefix, String property, Class<?> bean) { try { return bean.getMethod(prefix + capitalize(property)); } catch (NoSuchMethodException e) { return null; } }
@Nullable public static Method getGetterOrNull(Class<?> beanClass, String name, Class<?> type) { String methodName = ((type.equals(Boolean.class) || type.equals(boolean.class)) ? "is" : "get") + BeanUtils.capitalize(name); while (beanClass != null && !beanClass.equals(Object.class)) { try { return beanClass.getDeclaredMethod(methodName); } catch (SecurityException e) { // skip } catch (NoSuchMethodException e) { // skip } beanClass = beanClass.getSuperclass(); } return null; }
@Test public void capitalize() { assertEquals("X", BeanUtils.capitalize("x")); assertEquals("Prop", BeanUtils.capitalize("prop")); assertEquals("URL", BeanUtils.capitalize("URL")); assertEquals("cId", BeanUtils.capitalize("cId")); assertEquals("sEPOrder", BeanUtils.capitalize("sEPOrder")); }
private void assertReturnType(Method method) { assertEquals(BeanUtils.capitalize(method.getName()), method.getReturnType().getSimpleName()); }
String propertyName = property.getEscapedName(); writer.beginPublicMethod(property.getType(), "get" + BeanUtils.capitalize(propertyName)); writer.line("return ", propertyName, ";"); writer.end(); writer.beginPublicMethod(Types.VOID, "set" + BeanUtils.capitalize(propertyName), parameter); writer.line("this.", propertyName, " = ", propertyName, ";"); writer.end();
@Test public void uncapitalize() { assertEquals("x", BeanUtils.uncapitalize("X")); assertEquals("prop", BeanUtils.uncapitalize("Prop")); assertEquals("URL", BeanUtils.uncapitalize("URL")); assertEquals("cId", BeanUtils.uncapitalize("cId")); assertEquals("sEPOrder", BeanUtils.capitalize("sEPOrder")); }
public static Method getAccessor(String prefix, String property, Class<?> bean) { try { return bean.getMethod(prefix + capitalize(property)); } catch (NoSuchMethodException e) { return null; } }
public static boolean isAccessorPresent(String prefix, String property, Class<?> bean) { try { bean.getMethod(prefix + capitalize(property)); return true; } catch (NoSuchMethodException ex) { return false; } }
@Nullable public static Method getGetterOrNull(Class<?> beanClass, String name, Class<?> type) { String methodName = ((type.equals(Boolean.class) || type.equals(boolean.class)) ? "is" : "get") + BeanUtils.capitalize(name); while (beanClass != null && !beanClass.equals(Object.class)) { try { return beanClass.getDeclaredMethod(methodName); } catch (SecurityException e) { // skip } catch (NoSuchMethodException e) { // skip } beanClass = beanClass.getSuperclass(); } return null; }
/** * 获取Bean的属性Setter。 */ @SuppressWarnings("unchecked") public static Method findSetter(Object bean, String name, Class type) { Assert.notNull(bean, "Bean param missing"); String methodName = "set" + BeanUtils.capitalize(name); Class beanClass = bean.getClass(); while (beanClass != null && !beanClass.equals(Object.class)) { try { return beanClass.getDeclaredMethod(methodName, type); } catch (SecurityException | NoSuchMethodException e) { // 跳过当前类并从父类查找 beanClass = beanClass.getSuperclass(); } } return null; }
String propertyName = property.getEscapedName(); writer.beginPublicMethod(property.getType(), "get" + BeanUtils.capitalize(propertyName)); writer.line("return ", propertyName, ";"); writer.end(); writer.beginPublicMethod(Types.VOID, "set" + BeanUtils.capitalize(propertyName), parameter); writer.line("this.", propertyName, " = ", propertyName, ";"); writer.end();
String propertyName = property.getEscapedName(); writer.beginPublicMethod(property.getType(), "get" + BeanUtils.capitalize(propertyName)); writer.line("return ", propertyName, ";"); writer.end(); writer.beginPublicMethod(Types.VOID, "set" + BeanUtils.capitalize(propertyName), parameter); writer.line("this.", propertyName, " = ", propertyName, ";"); writer.end();
String propertyName = property.getEscapedName(); writer.beginPublicMethod(property.getType(), "get" + BeanUtils.capitalize(propertyName)); writer.line("return ", propertyName, ";"); writer.end(); writer.beginPublicMethod(Types.VOID, "set" + BeanUtils.capitalize(propertyName), parameter); writer.line("this.", propertyName, " = ", propertyName, ";"); writer.end();