org.as2lib.core.BasicClass +--org.as2lib.env.reflect.ClassInfo
TypeInfo
ClassInfo
reflects a class and provides methods to get information about
that class.
The static search methods forName, forObject, forInstance and forClass can be used to get class infos for specific classes.
If you for example want to get information about the class of a specific instance
you can retrieve the appropriate ClassInfo
instance and you can then use
its methods to get the information you wanted.
Example:
var myInstance:MyClass = new MyClass();
var classInfo:ClassInfo = ClassInfo.forInstance(myInstance);
trace("Class Name: " + classInfo.getFullName());
trace("Super Class Name: " + classInfo.getSuperType().getFullName());
trace("Declared Methods: " + classInfo.getMethods(true));
trace("Declared Properties: " + classInfo.getProperties(true));
Note that right now it is not possible to distinguish between interfaces and
classes at run-time. Therefore are both classes and interfaces reflected by
ClassInfo
instances. This is going to change as soon is the differentiation
is possible.
new ClassInfo()
public function ClassInfo(clazz:Function, name:String, package:PackageInfo)
Constructs a new ClassInfo
instance.
Note that the argument clazz
is not mandatorily necessary, although
most of the methods cannot do their job correctly if it is null
or
undefined
.
If you do not pass-in the name
or the package
they will be
resolved lazily when requested using the passed-in clazz
.
clazz | the class this new class info reflects |
name | (optional) the name of the reflected class |
package | (optional) the package the reflected class is a member of |
static public function forName(className:String):ClassInfo
Returns the class info corresponding to the passed-in fully qualified
className
.
Fully qualified means that className
must consist of the class's
namespace (preceding package structure) as well as its name. For example
"org.as2lib.core.BasicClass"
.
This method first checks whether the class info for the class with the given
className
is already contained in the cache and adds it to the cache if
not.
className | the fully qualified class name |
the class info reflecting the class corresponding to the className
IllegalArgumentException | if the passed-in className is null ,
undefined or an empty string or if the object corresponding to the
passed-in className is not of type function
|
ClassNotFoundException | if a class with the passed-in className
could not be found
|
static public function forObject(object):ClassInfo
Returns the class info corresponding to the passed-in object
.
If the passed-in object
is of type function
it is supposed
that it is the class you want to get the class info for. Otherwise it is supposed
that the object is an instance of the class you want to get the class info for.
This method first checks whether the class info for the given class or for the class of the given instance is already contained in the cache and adds it to the cache if not.
object | the object you want to get the class info for |
the class info corresponding to the passed-in object
IllegalArgumentException | if the passed-in object is null
or undefined
|
ClassNotFoundException | if the class corresponding to the passed-in
object could not be found
|
static public function forInstance(instance):ClassInfo
Returns the class info corresponding to the class of the passed-in
instance
This method first checks whether the class info for the class of the given
instance
is already contained in the cache and adds it to the cache if
not.
instance | the instance you want to get the class info for |
the class info reflecting the class of the passed-in instance
IllegalArgumentException | if the passed-in instance is
null or undefined
|
ClassNotFoundException | if the class corresponding to the passed-in
instance could not be found
|
static public function forClass(clazz:Function):ClassInfo
Returns the class info corresponding to the passed-in clazz
.
This method first checks whether the class info for the given clazz
is already contained in the cache and adds it to the cache if not.
clazz | the class you want to get the class info for |
the class info reflecting the passed-in clazz
IllegalArgumentException | if the passed-in clazz is null
or undefined
|
static public function setClassAlgorithm(newClassAlgorithm:ClassAlgorithm):Void
Sets the algorithm used to find classes.
If the passed-in newClassAlgorithm
is of value null
or
undefined
, the getClassAlgorithm method will return the default
class algorithm.
newClassAlgorithm | the new class algorithm to find classes |
static public function getClassAlgorithm(Void):ClassAlgorithm
Returns the class algorithm used to find classes.
Either the algorithm set via the setClassAlgorithm method will be returned or the default one which is an instance of class ClassAlgorithm.
the set or the default class algorithm
static public function setMethodAlgorithm(newMethodAlgorithm:MethodAlgorithm):Void
Sets the algorithm used to find methods.
If the passed-in newMethodAlgorithm
is of value null
or
undefined
, the getMethodAlgorithm method will return the
default method algorithm.
newMethodAlgorithm | the new method algorithm to find methods |
static public function getMethodAlgorithm(Void):MethodAlgorithm
Returns the method algorithm used to find methods.
Either the algorithm set via the setMethodAlgorithm method will be returned or the default one which is an instance of class MethodAlgorithm.
the set or the default method algorithm
static public function setPropertyAlgorithm(newPropertyAlgorithm:PropertyAlgorithm):Void
Sets the algorithm used to find properties.
If the passed-in newPropertyAlgorithm
is of value null
or
undefined
, the getPropertyAlgorithm method will return the
default property algorithm.
newPropertyAlgorithm | the new property algorithm to find properties |
static public function getPropertyAlgorithm(Void):PropertyAlgorithm
Returns the property algorithm used to find properties.
Either the algorithm set via the setPropertyAlgorithm method will be returned or the default one which is an instance of class PropertyAlgorithm.
the set or the default property algorithm
public function getName(Void):String
Returns the name of the represented class without its namespace.
The namespace is the package path to the class. The namespace of the class 'org.as2lib.core.BasicClass' is 'org.as2lib.core'. In this example this method would only return 'BasicClass'.
public function getFullName(Void):String
Returns the fully qualified name of the represented class. That means the name of the class plus its package path, namespace.
The path will not be included if:
null
or undefined
. isRoot
method of the package returned by getPackage
returns true
.
the fully qualified name of the represented class
public function getType(Void):Function
Returns the actual class this class info represents.
the represented class
public function getConstructor(Void):ConstructorInfo
Returns the class's constructor representation.
You can use the returned constructor info to get the actual
constructor. Note that the constructor in Flash is by default the same as the
class. Thus the function returned by the getType method and the
getMethod
method of the returned constructor is the same, if you did not
overwrite the constructor manually after this instance was created.
the constructor of the class
public function getSuperType(Void):TypeInfo
Returns the super class of the class this instance represents.
The returned instance is of type ClassInfo
and can thus be casted to
this type.
null
will be returned if:
Object
. null
. the super class of the class this instance represents or null
public function newInstance()
Creates a new instance of the represented class passing the constructor arguments.
null
will be returned if the getType method returns
null
or undefined
.
... | any number of arguments to pass-to the constructor on creation |
a new instance of this class
public function getPackage(Void):PackageInfo
Returns the package the represented class is a member of.
The package of the class org.as2lib.core.BasicClass
is
org.as2lib.core
.
the package the represented class is a member of
public function hasMethod(methodName:String, filterStaticMethods:Boolean):Boolean
Returns whether this class or any super-class implements a method with the
passed-in methodName
.
Static methods are not filtered by default. That means filterStaticMethods
is by default set to false
.
If the passed-in methodName
is null
or undefined
,
false
will be returned.
methodName | the name of the method to search for |
filterStaticMethods | (optional) determines whether static methods are filtered, that means excluded from the search |
true
if the method exists else false
public function getMethodsByFlag(filterSuperClasses:Boolean):Array
Returns an array containing the methods represented by MethodInfo instances this type declares and maybe the ones of the super-classes.
The super-classes' methods are included if you filterSuperTypes
is
false
, null
or undefined
and excluded/filtered if it is
true
. This means that by default super-classes are not filtered.
null
will be returned if:
null
or undefined
. null
or undefined
.filterSuperClasses | (optional) determines whether the super classes' methods shall be excluded/filtered |
an array containing the methods
public function getMethodsByFilter(methodFilter:TypeMemberFilter):Array
Returns an array that contains the methods represented by MethodInfo instances, this class and super classes' declare, that are not filtered/excluded.
The TypeMemberFilter.filter method of the passed-in methodFilter
is invoked for every method to determine whether it shall be contained in the
result. The passed-in argument is of type MethodInfo
.
If the passed-in methodFilter
is null
or undefined
the result of an invocation of the getMethodsByFlag method with
argument false
will be returned.
null
will be returned if:
null
or undefined
. null
or undefined
.
methodFilter | the filter that filters unwanted methods out |
an array containing the declared methods that are not filtered, an empty
array if no methods are declared or all were filtered or null
public function getMethodByName(methodName:String):MethodInfo
Returns the method info corresponding to the passed-in methodName
.
null
will be returned if:
methodName
is null
or undefined
. methodName
is not declared in the represented
class or any super class.
If this class overwrites a method of any super class the, MethodInfo
instance of the overwriting method will be returned.
The declaring type of the returned method info is not always the one represented by this class. It can also be a super class of it.
methodName | the name of the method to return |
a method info representing the method corresponding to the methodName
public function getMethodByMethod(concreteMethod:Function):MethodInfo
Returns the method info corresponding to the passed-in concreteMethod
.
null
will be returned if:
concreteMethod
is null
or undefined
. concreteMethod
cannot be found on the
represented class or any super class.
The declaring class of the returned method info is not always the one represented by this class. It can also be a super class of it.
concreteMethod | the concrete method the method info shall be returned for |
the method info thate represents the passed-in concreteMethod
public function hasProperty(propertyName:String, filterStaticProperties:Boolean):Boolean
Returns whether this class or any super-class implements a property with the
passed-in propertyName
.
Static properties are not filtered by default. That means filterStaticProperties
is by default set to false
.
If the passed-in propertyName
is null
or undefined
,
false
will be returned.
propertyName | the name of the property to search for |
filterStaticProperties | (optional) determines whether static properties are filtered, that means excluded from the search |
true
if the property exists else false
public function getPropertiesByFlag(filterSuperClasses:Boolean):Array
Returns an array containing the properties represented by PropertyInfo instances this class declares and maybe the ones of the super-classes.
The super-classes' properties are included if filterSuperClasses
is
false
, null
or undefined
and excluded/filtered if it is
true
. This means that super-classes are by default not filtered.
null
will be returned if:
null
or undefined
. null
or undefined
.filterSuperClasses | (optional) determines whether the super classes' properties shall be excluded/filtered |
an array containing the properties
public function getPropertiesByFilter(propertyFilter:TypeMemberFilter):Array
Returns an array containing the properties represented by PropertyInfo instances this class and super classes' declare that are not filtered/excluded.
The TypeMemberFilter.filter method of the passed-in propertyFilter
is invoked for every property to determine whether it shall be contained in the
result.
If the passed-in propertyFilter
is null
or undefined
the result of the invocation of getPropertiesByFlag with argument
false
will be returned.
null
will be returned if:
null
or undefined
. null
or undefined
.propertyFilter | the filter that filters unwanted properties out |
an array containing the remaining properties
public function getPropertyByName(propertyName:String):PropertyInfo
Returns the property info corresponding to the passed-in propertyName
.
null
will be returned if:
propertyName
is null
or undefined
. propertyName
does not exist on the
represented class or any super class.
If this class overwrites a property of any super class the PropertyInfo
instance of the overwriting property will be returned.
The declaring class of the returned property info is not always the one represented by this class. It can also be a super class of it.
propertyName | the name of the property you wanna obtain |
the property info correspoinding to the passed-in propertyName
public function getPropertyByProperty(concreteProperty:Function):PropertyInfo
Returns the property info corresponding to the passed-in concreteProperty
.
null
will be returned if:
concreteProperty
is null
or undefined
. concreteProperty
cannot
be found on the represented class or any super class.
The declaring class of the returned property info is not always the one represented by this class. It can also be a super class of it.
concreteProperty | the concrete property to return the corresponding property info for |
the property info correspoinding to the passed-in concreteProperty
public function toString():String
Returns the string representation of this instance.
The string representation is constructed as follows:
[reflection fullyQualifiedNameOfReflectedType]
this instance's string representation
toString() in org.as2lib.core.BasicInterface