#15 Performance optimization for Reflect.hasObjectPropertySetter

open
nobody
None
5
2006-09-08
2006-09-08
Anonymous
No

public static boolean hasObjectPropertySetter(
Class clas, String propName )
{
String setterName = accessorName("set",
propName );

// FIXME: SMALL OPTIMIZATION: TRY TO GET A
GETTER METHOD FOR THIS PROPERTY AND DETERMINE
// ITS RESULT TYPE; THIS SHOULD GIVE A VERY
LIKELY SETTER METHOD ARGUMENT TYPE
try {
String accessorName = accessorName
( "get", propName );
Method method = clas.getMethod(
accessorName, zeroLengthClassArray );
Class argtype = method.getReturnType();
Class[] args = { argtype };
method = clas.getMethod(setterName,
args);
return true;
} catch ( Exception e ) {}
// FIXME: END OF OPTIMIZATION

Method [] methods = clas.getMethods();

// we don't know the right hand side of the
assignment yet.
// has at least one setter of the right name?
// FIXME: THIS DOESN'T APPEAR TO BE CORRECT,
BECAUSE IT DOESN'T TRAVERSE SUPER CLASSES
for(int i=0; i<methods.length; i++)
if ( methods[i].getName().equals(
setterName ) )
return true;
return false;
}

Discussion