public void defineProperty ( String propertyName , Class < ? > clazz , int attributes ) { int length = propertyName . length ( ) ; if ( length == 0 ) throw new IllegalArgumentException ( ) ; char [ ] buf = new char [ 3 + length ] ; propertyName . getChars ( 0 , length , buf , 3 ) ; buf [ 3 ] = Character . toUpperCase ( buf [ 3 ] ) ; buf [ 0 ] = ' ' ; buf [ 1 ] = ' ' ; buf [ 2 ] = ' ' ; String getterName = new String ( buf ) ; buf [ 0 ] = ' ' ; String setterName = new String ( buf ) ; Method [ ] methods = FunctionObject . getMethodList ( clazz ) ; Method getter = FunctionObject . findSingleMethod ( methods , getterName ) ; Method setter = FunctionObject . findSingleMethod ( methods , setterName ) ; if ( setter == null ) attributes |= ScriptableObject . READONLY ; defineProperty ( propertyName , null , getter , setter == null ? null : setter , attributes ) ; }
Define a JavaScript property with getter and setter side effects .