@@ -314,42 +314,34 @@ private Field findField(String name, Class<?> clazz, Object target) {
314314 * Find a getter method for the specified property.
315315 */
316316 protected Method findGetterForProperty (String propertyName , Class <?> clazz , boolean mustBeStatic ) {
317- Method [] ms = getSortedClassMethods (clazz );
318- String propertyMethodSuffix = getPropertyMethodSuffix (propertyName );
319-
320- // Try "get*" method...
321- String getterName = "get" + propertyMethodSuffix ;
322- for (Method method : ms ) {
323- if (method .getName ().equals (getterName ) && method .getParameterTypes ().length == 0 &&
324- (!mustBeStatic || Modifier .isStatic (method .getModifiers ()))) {
325- return method ;
326- }
327- }
328- // Try "is*" method...
329- getterName = "is" + propertyMethodSuffix ;
330- for (Method method : ms ) {
331- if (method .getName ().equals (getterName ) && method .getParameterTypes ().length == 0 &&
332- (boolean .class .equals (method .getReturnType ()) || Boolean .class .equals (method .getReturnType ())) &&
333- (!mustBeStatic || Modifier .isStatic (method .getModifiers ()))) {
334- return method ;
335- }
336- }
337- return null ;
317+ return findMethodForProperty (getPropertyMethodSuffixes (propertyName ),
318+ new String [] { "get" , "is" }, clazz , mustBeStatic , 0 );
338319 }
339320
340321 /**
341322 * Find a setter method for the specified property.
342323 */
343324 protected Method findSetterForProperty (String propertyName , Class <?> clazz , boolean mustBeStatic ) {
325+ return findMethodForProperty (getPropertyMethodSuffixes (propertyName ),
326+ new String [] { "set" }, clazz , mustBeStatic , 1 );
327+ }
328+
329+ private Method findMethodForProperty (String [] methodSuffixes , String [] prefixes , Class <?> clazz ,
330+ boolean mustBeStatic , int numberOfParams ) {
344331 Method [] methods = getSortedClassMethods (clazz );
345- String setterName = "set" + getPropertyMethodSuffix (propertyName );
346- for (Method method : methods ) {
347- if (method .getName ().equals (setterName ) && method .getParameterTypes ().length == 1 &&
348- (!mustBeStatic || Modifier .isStatic (method .getModifiers ()))) {
349- return method ;
332+ for (String methodSuffix : methodSuffixes ) {
333+ for (String prefix : prefixes ) {
334+ for (Method method : methods ) {
335+ if (method .getName ().equals (prefix + methodSuffix )
336+ && method .getParameterTypes ().length == numberOfParams
337+ && (!mustBeStatic || Modifier .isStatic (method .getModifiers ()))) {
338+ return method ;
339+ }
340+ }
350341 }
351342 }
352343 return null ;
344+
353345 }
354346
355347 /**
@@ -365,13 +357,29 @@ public int compare(Method o1, Method o2) {
365357 return methods ;
366358 }
367359
360+ /**
361+ * Return the method suffixes for a given property name. The default implementation
362+ * uses JavaBean conventions with additional support for properties of the form 'xY'
363+ * where the method 'getXY()' is used in preference to the JavaBean convention of
364+ * 'getxY()'.
365+ */
366+ protected String [] getPropertyMethodSuffixes (String propertyName ) {
367+ String suffix = getPropertyMethodSuffix (propertyName );
368+ if (suffix .length () > 0 && Character .isUpperCase (suffix .charAt (0 ))) {
369+ return new String [] { suffix };
370+ }
371+ return new String [] { suffix , StringUtils .capitalize (suffix ) };
372+ }
373+
374+ /**
375+ * Return the method suffix for a given property name. The default implementation
376+ * uses JavaBean conventions.
377+ */
368378 protected String getPropertyMethodSuffix (String propertyName ) {
369379 if (propertyName .length () > 1 && Character .isUpperCase (propertyName .charAt (1 ))) {
370380 return propertyName ;
371381 }
372- else {
373- return StringUtils .capitalize (propertyName );
374- }
382+ return StringUtils .capitalize (propertyName );
375383 }
376384
377385 /**
0 commit comments