Access keys

ClassInfo

Kind of class: class
Inherits from: BasicClass
Implements:
Author: Simon Wacker
Classpath: org.as2lib.env.reflect.ClassInfo
File last modified: Wednesday, 17 August 2005, 11:52:16
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.

Constructor

ClassInfo

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.

Parameters:
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

Class methods

forClass

static 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.

Parameters:
clazz:
the class you want to get the class info for
Returns:
the class info reflecting the passed-in clazz
Throws:
org.as2lib.env.except.IllegalArgumentException if the passed-in clazz is null
or undefined

forInstance

static 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.

Parameters:
instance:
the instance you want to get the class info for
Returns:
the class info reflecting the class of the passed-in instance
Throws:
org.as2lib.env.except.IllegalArgumentException if the passed-in instance is
null or undefined
ClassNotFoundException if the class corresponding to the passed-in
instance could not be found

forName

static 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.

Parameters:
className:
the fully qualified class name
Returns:
the class info reflecting the class corresponding to the className
Throws:
org.as2lib.env.except.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

forObject

static 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.

Parameters:
object:
the object you want to get the class info for
Returns:
the class info corresponding to the passed-in object
Throws:
org.as2lib.env.except.IllegalArgumentException if the passed-in object is null
or undefined
ClassNotFoundException if the class corresponding to the passed-in
object could not be found

getClassAlgorithm

static function getClassAlgorithm (
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 org.as2lib.env.reflect.algorithm.ClassAlgorithm.

Returns:
the set or the default class algorithm

getMethodAlgorithm

static function getMethodAlgorithm (
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 org.as2lib.env.reflect.algorithm.MethodAlgorithm.

Returns:
the set or the default method algorithm

getPropertyAlgorithm

static function getPropertyAlgorithm (
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
org.as2lib.env.reflect.algorithm.PropertyAlgorithm.

Returns:
the set or the default property algorithm

setClassAlgorithm

static 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.

Parameters:
newClassAlgorithm:
the new class algorithm to find classes

setMethodAlgorithm

static 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.

Parameters:
newMethodAlgorithm:
the new method algorithm to find methods

setPropertyAlgorithm

static 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.

Parameters:
newPropertyAlgorithm:
the new property algorithm to find properties

Instance methods

getConstructor

function getConstructor (
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.

Returns:
the constructor of the class

getFullName

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:

  • The getPackage method returns null or undefined.
  • The isRoot method of the package returned by getPackage
    returns true.
Returns:
the fully qualified name of the represented class
See also:

getMethodByMethod

function getMethodByMethod (
concreteMethod:Function) : MethodInfo
Returns the method info corresponding to the passed-in concreteMethod.

null will be returned if:

  • The passed-in concreteMethod is null or undefined.
  • A method matching the given 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.

Parameters:
concreteMethod:
the concrete method the method info shall be returned for
Returns:
the method info thate represents the passed-in concreteMethod

getMethodByName

function getMethodByName (
methodName:String) : MethodInfo
Returns the method info corresponding to the passed-in methodName.

null will be returned if:

  • The passed-in methodName is null or undefined.
  • A method with the given 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.

Parameters:
methodName:
the name of the method to return
Returns:
a method info representing the method corresponding to the methodName

getMethodsByFilter

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:

Parameters:
methodFilter:
the filter that filters unwanted methods out
Returns:
an array containing the declared methods that are not filtered, an empty
array if no methods are declared or all were filtered or null

getMethodsByFlag

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:

  • The getType method returns null or undefined.
  • The method algorithm returns null or undefined.
Parameters:
filterSuperClasses:
(optional) determines whether the super classes' methods
shall be excluded/filtered
Returns:
an array containing the methods

getName

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'.
@reutrn the name of the represented class

See also:
Returns:
this member's name
#
Specified by:

getPackage

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.

Returns:
the package the represented class is a member of
Specified by:

getPropertiesByFilter

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:

  • The getType method returns null or undefined.
  • The property algorithm returns null or undefined.
Parameters:
propertyFilter:
the filter that filters unwanted properties out
Returns:
an array containing the remaining properties

getPropertiesByFlag

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:

  • The getType method returns null or undefined.
  • The property algorithm returns null or undefined.
Parameters:
filterSuperClasses:
(optional) determines whether the super classes'
properties shall be excluded/filtered
Returns:
an array containing the properties

getPropertyByName

function getPropertyByName (
propertyName:String) : PropertyInfo
Returns the property info corresponding to the passed-in propertyName.

null will be returned if:

  • The passed-in propertyName is null or undefined.
  • A property with the given 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.

Parameters:
propertyName:
the name of the property you wanna obtain
Returns:
the property info correspoinding to the passed-in propertyName

getPropertyByProperty

function getPropertyByProperty (
concreteProperty:Function) : PropertyInfo
Returns the property info corresponding to the passed-in concreteProperty.

null will be returned if:

  • The passed-in concreteProperty is null or undefined.
  • A property corresponding to the passed-in 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.

Parameters:
concreteProperty:
the concrete property to return the corresponding
property info for
Returns:
the property info correspoinding to the passed-in concreteProperty

getSuperType

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:

  • The represented class is Object.
  • The represented class has no prototype.
  • The static forInstance method returns null.
Returns:
the super class of the class this instance represents or null
Specified by:

getType

function getType (
Void) : Function
Returns the actual class this class info represents.
Returns:
the represented class
Specified by:

hasMethod

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.

Parameters:
methodName :
the name of the method to search for
filterStaticMethods:
(optional) determines whether static methods are
filtered, that means excluded from the search
Returns:
true if the method exists else false
Specified by:

hasProperty

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.

Parameters:
propertyName :
the name of the property to search for
filterStaticProperties:
(optional) determines whether static properties are
filtered, that means excluded from the search
Returns:
true if the property exists else false

newInstance

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.

Parameters:
..:
any number of arguments to pass-to the constructor on creation
Returns:
a new instance of this class

toString

function toString (
) : String
Returns the string representation of this instance.

The string representation is constructed as follows:

[reflection fullyQualifiedNameOfReflectedType]
Parameters:
displayContent:
(optional) a Boolean that determines whether to
render all methods true or not false
Returns:
this instance's string representation