public static JMethod getGetter(JClassType beanType, String fieldName) throws NotFoundException { JMethod method = null; try { try { method = beanType.getMethod("get" + getterSetterDeterminator(fieldName), new JType[0]); } catch (NotFoundException e) { method = beanType.getMethod("is" + getterSetterDeterminator(fieldName), new JType[0]); } } catch (NotFoundException e) { JClassType superClass = beanType.getSuperclass(); if (superClass != null) { try { method = getGetter(superClass, fieldName); } catch (NotFoundException e1) { JClassType[] interfaces = beanType.getImplementedInterfaces(); if (interfaces != null && interfaces.length > 0) { for (JClassType intrface : interfaces) { method = getGetter(intrface, fieldName); if (method != null) { break; } } } } } } return method; }
String setterName = "set" + getterSetterDeterminator(fieldName);
public static JMethod getSetter(JClassType beanType, String fieldName, JType fieldType) throws NotFoundException { JMethod method = null; try { method = beanType.getMethod("set" + getterSetterDeterminator(fieldName), new JType[] { fieldType }); if (method.isPrivate()) method = null; } catch (NotFoundException e) { JClassType superClass = beanType.getSuperclass(); if (superClass != null) { try { method = getSetter(superClass, fieldName, fieldType); } catch (NotFoundException e1) { JClassType[] interfaces = beanType.getImplementedInterfaces(); if (interfaces != null && interfaces.length > 0) { for (JClassType intrface : interfaces) { method = getSetter(intrface, fieldName, fieldType); if (method != null) { break; } } } } } } return method; }