Packagesystem
Classpublic class Reflection
InheritanceReflection Inheritance Object

Provides a basic reflection mecanisms on the language.

Example :

     import system.Arrays ;
     
     import system.data.Map ;
     import system.data.maps.HashMap ;
     
     import system.reflection.ClassInfo ;
     import system.Reflection ;
     
     import system.Serializable ;
     
     trace( "# Object isDynamic() : " + Reflection.getClassInfo(Object).isDynamic() ) ; // # Object isDynamic() : true
     trace( "# String isFinal()   : " + Reflection.getClassInfo(String).isFinal()   ) ; // # String isFinal()   : true
     trace( "# Math isStatic()    : " + Reflection.getClassInfo(Math).isStatic()    ) ; // # Math isStatic()   : true
     
     trace("---------") ;
     
     var map:HashMap = new HashMap() ;
     
     var classInfo:ClassInfo ;
     classInfo = Reflection.getClassInfo( map ) ;
     
     trace( "# isInstance() : " + classInfo.isInstance() ) ; // # isInstance() : true
     trace( "# isDynamic()  : " + classInfo.isDynamic()  ) ; // # isDynamic()  : false
     trace( "# isFinal()    : " + classInfo.isFinal()    ) ; // # isFinal()    : false
     trace( "# isStatic()   : " + classInfo.isStatic()   ) ; // # isStatic()   : false
     
     trace( "# hasInterface( Map , Serializable ) : " + classInfo.hasInterface( Map , Serializable )  ) ; // # hasInterface( Map , Serializable ) : true
     trace( "# inheritFrom( Object ) : " + classInfo.inheritFrom( Object )  ) ; // # inheritFrom( Object ) : true
     
     trace("---------") ;
     
     classInfo = Reflection.getClassInfo(Reflection) ;
     
     trace( "# Reflection isStatic() : "  + classInfo.isStatic() ) ; // # Reflexion isStatic() : true
     
     trace( "---" ) ;
     
     trace( "# hasClassByName('system.data.maps.HashMap')      : " + Reflection.hasClassByName("system.data.maps.HashMap") ) ; // hasClassByName('system.data.maps.HashMap') : true
     trace( "# getClassByName('system.data.maps.HashMap')      : " + Reflection.getClassByName("system.data.maps.HashMap") ) ; // getClassByName('system.data.maps.HashMap') : [class HashMap]
     trace( "# getDefinitionByName('system.data.maps.HashMap') : " + Reflection.getDefinitionByName("system.data.maps.HashMap") ) ; // getDefinitionByName('system.data.maps.HashMap') : [class HashMap]
     
     trace( "---" ) ;
     
     trace( "# getClassName(map)      : " + Reflection.getClassName(map) )       ; // getClassName(map)      : HashMap
     trace( "# getClassName(map,true) : " + Reflection.getClassName(map, true) ) ; // getClassName(map,true) : system.data.maps::HashMap
     trace( "# getClassPackage(map)   : " + Reflection.getClassPackage(map) )    ; // getClassPackage(map)   : system.data.maps
     trace( "# getClassPath(map)      : " + Reflection.getClassPath(map) )       ; // getClassPath(map)      : system.data.maps.HashMap
     
     trace( "# getClassMethods(map)        : " + Reflection.getClassMethods(map)        ) ; // getClassMethods(map)         : put,clone,remove,keyIterator,containsKey,toSource,size,toString,putAll,getKeys,get,clear,iterator,containsValue,getValues,isEmpty
     trace( "# getClassMethods(map,true)   : " + Reflection.getClassMethods(map,true)   ) ; // getClassMethods(map,true)    : put,clone,remove,keyIterator,containsKey,toSource,size,toString,putAll,getKeys,get,clear,iterator,containsValue,getValues,isEmpty
     trace( "# getMethodByName(map,'put')  : " + Reflection.getMethodByName(map,"put")  ) ; // getMethodByName(map, 'put')  : function Function() {}
     trace( "# getMethodByName(map,'test') : " + Reflection.getMethodByName(map,"test") ) ; // getMethodByName(map, 'test') : null
     
     trace( "# getSuperClassName(core)    : " + Reflection.getSuperClassName(map) )    ; // getSuperClassName(map)     : Object
     trace( "# getSuperClassPackage(core) : " + Reflection.getSuperClassPackage(map) ) ; // getSuperClassPackage(map)  : null
     trace( "# getSuperClassPath(core)    : " + Reflection.getSuperClassPath(map) )    ; // getSuperClassPath(map)     : Object
     
     trace("---------") ;
     
     Array.prototype.toString = function():String
     {
         return "[" + this.join(",") + "]" ;
     }
     
     var ar:Array
     
     // test with no argument
     ar = Reflection.invokeClass( Array ) ;
     trace( ar ) ;
     //output: []
     
     // test with 0 argument
     ar = Reflection.invokeClass( Array , [] ) ;
     trace( ar ) ;
     //output: []
     
     // test with 2 arguments
     ar = Reflection.invokeClass( Array , Arrays.initialize(2,0) ) ;
     trace( ar ) ;
     //output: [0,0]
     
     // test with 32 arguments
     ar = Reflection.invokeClass( Array , Arrays.initialize(32,0) ) ;
     trace( ar ) ;
     //output: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
     
     // test with 33 arguments
     
     try
     {
         ar = Reflection.invokeClass( Array , Arrays.initialize(33,0) ) ;
         trace( ar ) ;
     }
     catch( e:Error )
     {
         trace(e) ; // ArgumentError: Reflection.invokeClass() method failed : arguments limit exceeded, you can pass a maximum of 32 arguments.
     }
     



Public Methods
 MethodDefined By
  
getClassByName(name:String):Class
[static] Returns the class reference from a string class name.
Reflection
  
getClassInfo(o:*, ... filters):ClassInfo
[static] Returns the ClassInfo object of the specified object.
Reflection
  
getClassMethods(o:*, inherited:Boolean = false):Array
[static] Returns an array of public methods defined in the class of an object.
Reflection
  
getClassName(o:*, path:Boolean = false):String
[static] Returns the class name as string of an object.
Reflection
  
getClassPackage(o:*):String
[static] Returns the package string representation of the specified instance passed in arguments.
Reflection
  
getClassPath(o:*):String
[static] Returns the full path string representation of the specified instance passed in arguments (package + name).
Reflection
  
getDefinitionByName(name:String):Object
[static] Returns the instance of a public definition in the current Domain.
Reflection
  
getMethodByName(o:*, name:String):Function
[static] Returns the method reference of the specified object with the passed-in property name.
Reflection
  
getSuperClassName(o:*):String
[static] Returns the super class name as string of an object.
Reflection
  
[static] Returns the super class package string representation of the specified instance passed in arguments.
Reflection
  
getSuperClassPath(o:*):String
[static] Returns the super class path string representation of the specified instance passed in arguments.
Reflection
  
[static] Returns the TypeInfo object of the specified object.
Reflection
  
hasClassByName(name:String):Boolean
[static] Returns a boolean telling if the class exists from a string name.
Reflection
  
invokeClass(c:Class, args:Array = null):*
[static] Wrapping method which select which build method use according to the argument count (32 max).
Reflection
Method Detail
getClassByName()method
public static function getClassByName(name:String):Class

Returns the class reference from a string class name. The string name notation can be either "flash.system::Capabilities" or "flash.system.Capabilities" but you have to provide the full qualified path of the class "Capabilities" alone will not work.

Parameters

name:String

Returns
Class — the class reference from a string class name.
getClassInfo()method 
public static function getClassInfo(o:*, ... filters):ClassInfo

Returns the ClassInfo object of the specified object.

Parameters

o:*
 
... filters

Returns
ClassInfo — the ClassInfo object of the specified object.
getClassMethods()method 
public static function getClassMethods(o:*, inherited:Boolean = false):Array

Returns an array of public methods defined in the class of an object.

Parameters

o:*
 
inherited:Boolean (default = false)

Returns
Array — an array of public methods defined in the class of an object.
getClassName()method 
public static function getClassName(o:*, path:Boolean = false):String

Returns the class name as string of an object.

Parameters

o:*
 
path:Boolean (default = false)

Returns
String — the class name as string of an object.
getClassPackage()method 
public static function getClassPackage(o:*):String

Returns the package string representation of the specified instance passed in arguments.

Parameters

o:* — the reference of the object to apply reflexion.

Returns
String — the package string representation of the specified instance passed in arguments.
getClassPath()method 
public static function getClassPath(o:*):String

Returns the full path string representation of the specified instance passed in arguments (package + name).

Parameters

o:* — the reference of the object to apply reflexion.

Returns
String — the full path string representation of the specified instance passed in arguments (package + name).
getDefinitionByName()method 
public static function getDefinitionByName(name:String):Object

Returns the instance of a public definition in the current Domain. The definition can be a class, namespace, function or object.

Parameters

name:String

Returns
Object — the instance of a public definition in the current Domain.
getMethodByName()method 
public static function getMethodByName(o:*, name:String):Function

Returns the method reference of the specified object with the passed-in property name.

Parameters

o:*
 
name:String

Returns
Function — the method reference of the specified object with the passed-in property name.
getSuperClassName()method 
public static function getSuperClassName(o:*):String

Returns the super class name as string of an object.

Parameters

o:*

Returns
String — the super class name as string of an object.
getSuperClassPackage()method 
public static function getSuperClassPackage(o:*):String

Returns the super class package string representation of the specified instance passed in arguments.

Parameters

o:* — the reference of the object to apply reflexion.

Returns
String — the super class package string representation of the specified instance passed in arguments.
getSuperClassPath()method 
public static function getSuperClassPath(o:*):String

Returns the super class path string representation of the specified instance passed in arguments.

Parameters

o:* — the reference of the object to apply reflexion.

Returns
String — the super class path string representation of the specified instance passed in arguments.
getTypeInfo()method 
public static function getTypeInfo(o:*):TypeInfo

Returns the TypeInfo object of the specified object.

Parameters

o:*

Returns
TypeInfo — the TypeInfo object of the specified object.
hasClassByName()method 
public static function hasClassByName(name:String):Boolean

Returns a boolean telling if the class exists from a string name.

Parameters

name:String

Returns
Boolean — a boolean telling if the class exists from a string name.
invokeClass()method 
public static function invokeClass(c:Class, args:Array = null):*

Wrapping method which select which build method use according to the argument count (32 max).

Example :

         import system.Arrays ;
         import system.Reflection ;
         
         Array.prototype.toString = function():String
         {
             return "[" + this.join(",") + "]" ;
         }
         
         var ar:Array
         
         // test with no argument
         ar = Reflection.invokeClass( Array ) ;
         trace( ar ) ;
         //output: []
         
         // test with 0 argument
         ar = Reflection.invokeClass( Array , [] ) ;
         trace( ar ) ;
         //output: []
         
         // test with 2 arguments
         ar = Reflection.invokeClass( Array , Arrays.initialize(2,0) ) ;
         trace( ar ) ;
         //output: [0,0]
         
         // test with 32 arguments
         ar = Reflection.invokeClass( Array , Arrays.initialize(32,0) ) ;
         trace( ar ) ;
         //output: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
         
         // test with 33 arguments
         ar = Reflection.invokeClass( Array , Arrays.initialize(33,0) ) ;
         trace( ar ) ;
         
         //output:
         // ArgumentError: Reflection.invokeClass() method failed : arguments limit exceeded, you can pass a maximum of 32 arguments.
         

Parameters

c:Class — The Class of the instance to build.
 
args:Array (default = null) — The array of all arguments to passed-in the constructor of the specified class.

Returns
*