Class org.as2lib.env.reflect.ClassInfo

org.as2lib.core.BasicClass
   +--org.as2lib.env.reflect.ClassInfo

Implemented Interfaces

TypeInfo

Description

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.

Method Index

new ClassInfo()

forClass(), forInstance(), forName(), forObject(), getClassAlgorithm(), getConstructor(), getFullName(), getMethod(), getMethodAlgorithm(), getMethodByMethod(), getMethodByName(), getMethods(), getMethodsByFilter(), getMethodsByFlag(), getName(), getPackage(), getProperties(), getPropertiesByFilter(), getPropertiesByFlag(), getProperty(), getPropertyAlgorithm(), getPropertyByName(), getPropertyByProperty(), getSuperType(), getType(), hasMethod(), hasProperty(), newInstance(), setClassAlgorithm(), setMethodAlgorithm(), setPropertyAlgorithm(), toString()

Constructor Detail

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.

Parameters

clazzthe 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

Method Detail

forName

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.

Parameters

classNamethe fully qualified class name

Return

the class info reflecting the class corresponding to the className

Throws

IllegalArgumentExceptionif 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
ClassNotFoundExceptionif a class with the passed-in className could not be found

forObject

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.

Parameters

objectthe object you want to get the class info for

Return

the class info corresponding to the passed-in object

Throws

IllegalArgumentExceptionif the passed-in object is null or undefined
ClassNotFoundExceptionif the class corresponding to the passed-in object could not be found

forInstance

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.

Parameters

instancethe instance you want to get the class info for

Return

the class info reflecting the class of the passed-in instance

Throws

IllegalArgumentExceptionif the passed-in instance is null or undefined
ClassNotFoundExceptionif the class corresponding to the passed-in instance could not be found

forClass

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.

Parameters

clazzthe class you want to get the class info for

Return

the class info reflecting the passed-in clazz

Throws

IllegalArgumentExceptionif the passed-in clazz is null or undefined

setClassAlgorithm

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.

Parameters

newClassAlgorithmthe new class algorithm to find classes

getClassAlgorithm

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.

Return

the set or the default class algorithm

setMethodAlgorithm

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.

Parameters

newMethodAlgorithmthe new method algorithm to find methods

getMethodAlgorithm

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.

Return

the set or the default method algorithm

setPropertyAlgorithm

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.

Parameters

newPropertyAlgorithmthe new property algorithm to find properties

getPropertyAlgorithm

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.

Return

the set or the default property algorithm

getName

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

getFullName

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:

  • The getPackage method returns null or undefined.
  • The isRoot method of the package returned by getPackage returns true.

Return

the fully qualified name of the represented class

getType

public function getType(Void):Function

Returns the actual class this class info represents.

Return

the represented class

Specified By

getType() in org.as2lib.env.reflect.TypeInfo

getConstructor

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.

Return

the constructor of the class

getSuperType

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:

  • The represented class is Object.
  • The represented class has no prototype.
  • The static forInstance method returns null.

Return

the super class of the class this instance represents or null

Specified By

getSuperType() in org.as2lib.env.reflect.TypeInfo

newInstance

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.

Parameters

...any number of arguments to pass-to the constructor on creation

Return

a new instance of this class

getPackage

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.

Return

the package the represented class is a member of

Specified By

getPackage() in org.as2lib.env.reflect.TypeInfo

hasMethod

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.

Parameters

methodNamethe name of the method to search for
filterStaticMethods(optional) determines whether static methods are filtered, that means excluded from the search

Return

true if the method exists else false

Specified By

hasMethod() in org.as2lib.env.reflect.TypeInfo

getMethods

public function getMethods():Array

getMethodsByFlag

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:

  • 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

Return

an array containing the methods

Specified By

getMethodsByFlag() in org.as2lib.env.reflect.TypeInfo

getMethodsByFilter

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:

Parameters

methodFilterthe filter that filters unwanted methods out

Return

an array containing the declared methods that are not filtered, an empty array if no methods are declared or all were filtered or null

Specified By

getMethodsByFilter() in org.as2lib.env.reflect.TypeInfo

getMethod

public function getMethod():MethodInfo

getMethodByName

public 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

methodNamethe name of the method to return

Return

a method info representing the method corresponding to the methodName

Specified By

getMethodByName() in org.as2lib.env.reflect.TypeInfo

getMethodByMethod

public 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

concreteMethodthe concrete method the method info shall be returned for

Return

the method info thate represents the passed-in concreteMethod

Specified By

getMethodByMethod() in org.as2lib.env.reflect.TypeInfo

hasProperty

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.

Parameters

propertyNamethe name of the property to search for
filterStaticProperties(optional) determines whether static properties are filtered, that means excluded from the search

Return

true if the property exists else false

getProperties

public function getProperties():Array

getPropertiesByFlag

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:

  • 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

Return

an array containing the properties

getPropertiesByFilter

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:

  • The getType method returns null or undefined.
  • The property algorithm returns null or undefined.

Parameters

propertyFilterthe filter that filters unwanted properties out

Return

an array containing the remaining properties

getProperty

public function getProperty():PropertyInfo

getPropertyByName

public 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

propertyNamethe name of the property you wanna obtain

Return

the property info correspoinding to the passed-in propertyName

getPropertyByProperty

public 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

concretePropertythe concrete property to return the corresponding property info for

Return

the property info correspoinding to the passed-in concreteProperty

toString

public function toString():String

Returns the string representation of this instance.

The string representation is constructed as follows:

   [reflection fullyQualifiedNameOfReflectedType]
 

Parameters

Return

this instance's string representation

Specified By

toString() in org.as2lib.core.BasicInterface

Overrides

toString() in org.as2lib.core.BasicClass