Class org.as2lib.env.reflect.ReflectUtil

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

Description

ReflectUtil obtains simple information about members.

It is independent on any module of the As2lib. And thus does not include them and does not dramatically increase the file size.

Field Index

CONSTRUCTOR, UNKNOWN

Method Index

getMethodName(), getMethodNameByInstance(), getMethodNameByType(), getTypeAndMethodInfo(), getTypeAndMethodInfoByInstance(), getTypeAndMethodInfoByPrototype(), getTypeAndMethodInfoByType(), getTypeName(), getTypeNameForInstance(), getTypeNameForType(), getUnusedMemberName(), getVariableNames(), isConstructor(), isConstructorByInstance(), isConstructorByType(), isMethodStatic(), isMethodStaticByInstance(), isMethodStaticByType()

Inherited from BasicClass

toString()

Field Detail

CONSTRUCTOR

static public CONSTRUCTOR:String
The name to use for constructors.

UNKNOWN

static public UNKNOWN:String
The name to use for unknown information.

Method Detail

getUnusedMemberName

static public function getUnusedMemberName(object):String

Searches for a member name that is currently not used.

Uses MEMBER_PREFIX and a number from 1 to 10000 with two variants to find a member name that is currently not used (20.000 possible variants).

Parameters

objectthe object to find an unused member name in

Return

the name of the unused member or null if all names are already reserved

getTypeAndMethodInfo

static public function getTypeAndMethodInfo(object, method:Function):Array

getTypeAndMethodInfoByType

static public function getTypeAndMethodInfoByType(type:Function, method:Function):Array

Returns an array that contains the passed-in method's scope, the name of the type that declares the method and the name of the method itself.

The type that declares the method must not be the passed-in type. It may also be a super-type of the passed-in type.

null will be returned if the passed-in type is null.

Parameters

typethe type to start the search for the method
methodthe method to return information about

Return

an array containing the passed-in method's scope, the name of the declaring type and the passed-in method's name

getTypeAndMethodInfoByInstance

static public function getTypeAndMethodInfoByInstance(instance, method:Function):Array

Returns an array that contains the passed-in method's scope, the name of the type that declares the method and the name of the method itself.

The type that declares the method must not be the direct type of the passed-in instance. It may also be a super-type of this type.

null will be returned if the passed-in type is null.

Parameters

instancethe instance of the type to start the search for the method
methodthe method to return information about

Return

an array containing the passed-in method's scope, the name of the declaring type and the passed-in method's name

getTypeAndMethodInfoByPrototype

static public function getTypeAndMethodInfoByPrototype(p, m:Function):Array

Returns an array that contains the passed-in method's m scope, the name of the type that declares the method and the name of the method itself.

The type that declares the method must not be the direct type of the passed-in prototype p. It may also be a super-type of this type.

null will be returned if the passed-in prototype is null.

Parameters

pthe beginning of the prototype chain to search through
mthe method to return information about

Return

an array containing the passed-in method's scope, the name of the declaring type and the passed-in method's name

getTypeName

static public function getTypeName(object):String

getTypeNameForInstance

static public function getTypeNameForInstance(instance):String

Returns the name of the type, the passed-in object is an instance of.

null will be returned if:

  • The passed-in instance is null or undefined.
  • The appropriate type could not be found in _global.

Parameters

instancethe instance of the type to return the name of

Return

the name of the type of the instance or null

getTypeNameForType

static public function getTypeNameForType(type:Function):String

Returns the name of the passed-in type.

null will be returned if:

  • The passed-in type is null or undefined.
  • The type could not be found in _global.

Parameters

typethe type to return the name of

Return

the name of the passed-in type or null

getMethodName

static public function getMethodName(method:Function, object):String

getMethodNameByInstance

static public function getMethodNameByInstance(method:Function, instance):String

Returns the name of the method on the instance's type.

null will be returned if:

  • The passed-in method or instance are null
  • The method does not exist on the instance's type.

Parameters

methodthe method to get the name of
instancethe instance whose type implements the method

Return

the name of the method or null

getMethodNameByType

static public function getMethodNameByType(method:Function, type:Function):String

Returns the name of the method on the type.

null will be returned if:

  • The passed-in method or type are null
  • The method does not exist on the type.

Parameters

methodthe method to get the name of
typethe type that implements the method

Return

the name of the method or null

isMethodStatic

static public function isMethodStatic(methodName:String, object):Boolean

isMethodStaticByInstance

static public function isMethodStaticByInstance(methodName:String, instance):Boolean

Returns whether the method with the passed-in methodName is static, that means a per type method.

false will always be returned if the passed-in methodName is null or an empty string or if the passed-in instance is null.

Parameters

methodNamethe name of the method to check whether it is static
instancethe instance of the type that implements the method

Return

true if the method is static else false

isMethodStaticByType

static public function isMethodStaticByType(methodName:String, type:Function):Boolean

Returns whether the method with the passed-in methodName is static, that means a per type method.

false will always be returned if the passed-in methodName is null or an empty string or if the passed-in type is null.

Parameters

methodNamethe name of the method to check whether it is static
typethe type that implements the method

Return

true if the method is static else false

isConstructor

static public function isConstructor(constructor:Function, object):Boolean

isConstructorByInstance

static public function isConstructorByInstance(method:Function, instance):Boolean

Returns whether the passed-in method is the constructor of the passed-in instance.

false will always be returned if the passed-in method is null or if the passed-in instance is null.

Parameters

methodthe method to check whether it is the constructor of the passed-in instance
instancethe instance that might be instantiated by the passed-in method

Return

true if method is the constructor of instance else false

isConstructorByType

static public function isConstructorByType(method:Function, type:Function):Boolean

Returns whether the passed-in method is the constructor of the passed-in type.

Note that in Flash the constructor is the same as the type.

false will always be returned if the passed-in method is null or if the passed-in type is null.

Parameters

methodthe method to check whether it is the constructor of the passed-in type
typethe type that might declare the passed-in method as constructor

Return

true if method is the constructor of type else false

getVariableNames

static public function getVariableNames(instance):Array

Returns an array that contains the names of the variables of the passed-in instance as Strings.

The resulting array contains all variables' names even those hidden from for..in loops. Excluded are only "__proto__", "prototype", "__constructor__" and "constructor" and members that are of type "function".

Note that it is not possible to get variables that have been declared in the class but have not been initialized yet. These variables' names are thus not contained in the resulting array.

This method will never return null. If the passed-in instance has no variables an empty array will be returned.

Parameters

instancethe instance whose varaibles to return

Return

all initialized variables of the passed-in instance