Class
class ClassTypeInfo
public class ClassTypeInfo <: TypeInfo
Description: Describes type information of the class
type.
Parent Type:
prop constructors
public prop constructors: Collection<ConstructorInfo>
Description: Obtains information about all public constructors of the class
corresponding to ClassTypeInfo and returns the corresponding collection.
Note:
- If the
class
type does not have any public constructor, an empty collection is returned.- The collection does not guarantee a constant traversal sequence.
Type: Collection<ConstructorInfo>
prop instanceVariables
public prop instanceVariables: Collection<InstanceVariableInfo>
Description: Obtains information about all public instance variables of the class
corresponding to ClassTypeInfo and returns the corresponding collection.
Note:
- If the
class
type does not have any public instance variable, an empty collection is returned.- The collection does not guarantee a constant traversal sequence.
- The collection does not contain any inherited public instance variable.
Type: Collection<InstanceVariableInfo>
prop sealedSubclasses
public prop sealedSubclasses: Collection<ClassTypeInfo>
Description: Obtains the type information of all subclasses in the package to which the class
type belongs and returns the corresponding collection if the class
type corresponding to ClassTypeInfo has the sealed
semantics.
Note:
- If the
class
type does not have thesealed
semantics, an empty collection is returned.- If the
class
type has thesealed
semantics, the obtained collection cannot be an empty collection because theclass
type itself is its own subclass.
Type: Collection<ClassTypeInfo>
prop staticVariables
public prop staticVariables: Collection<StaticVariableInfo>
Description: Obtains information about all public static member variables of the class
corresponding to ClassTypeInfo and returns the corresponding collection.
Note:
- If the
class
type does not have any public static member variable, an empty collection is returned.- The collection does not guarantee a constant traversal sequence.
- The collection does not contain any inherited public static member variable.
Type: Collection<StaticVariableInfo>
prop superClass
public prop superClass: Option<ClassTypeInfo>
Description: Obtains the direct parent class of the class
type corresponding to the class
type information.
Note:
Theoretically, only class Object does not have a direct parent class.
Type: Option<ClassTypeInfo>
func construct(Array<Any>)
public func construct(args: Array<Any>): Any
Description: Searches for and calls a matched constructor based on the actual parameter list in the class
type corresponding to ClassTypeInfo, passes the actual parameter list, and returns the call result.
Parameters:
Returns:
- Any: instance of the
class
type
Throws:
- IllegalTypeException: If the
class
type has theabstract
semantics, this exception is thrown whenconstruct
is called because an abstract class cannot be instantiated. - MisMatchException: If
args
fails to match any public constructor of theclass
type, this exception is thrown. - InvocationTargetException: Any exception thrown inside the called constructor is encapsulated as InvocationTargetException and thrown.
func getConstructor(Array<TypeInfo>)
public func getConstructor(parameterTypes: Array<TypeInfo>): ConstructorInfo
Description: Attempts to obtain information about the public constructor that matches a given formal parameter type information list from the class
type corresponding to ClassTypeInfo.
Parameters:
Returns:
- ConstructorInfo: If a match is found, information about the public constructor is returned.
Throws:
- InfoNotFoundException: If no matched public constructor is found, this exception is thrown.
func getInstanceVariable(String)
public func getInstanceVariable(name: String): InstanceVariableInfo
Description: Attempts to obtain information about the matched instance variable in the class
type corresponding to ClassTypeInfo based on a given variable name.
Parameters:
- name: String: variable name
Returns:
- InstanceVariableInfo: If a match is found, information about the instance variable is returned.
Throws:
- InfoNotFoundException: If no matched instance variable is found, this exception is thrown.
func getStaticVariable(String)
public func getStaticVariable(name: String): StaticVariableInfo
Description: Attempts to obtain information about the matched static member variable in the class
type corresponding to ClassTypeInfo based on a given variable name.
Parameters:
- name: String: variable name
Returns:
- StaticVariableInfo: If a match is found, information about the static member variable is returned.
Throws:
- InfoNotFoundException: If no matched static member variable is found, this exception is thrown.
func isAbstract()
public func isAbstract(): Bool
Description: Checks whether the class
type corresponding to ClassTypeInfo is an abstract class.
Returns:
- Bool: If the
class
type corresponding to ClassTypeInfo is an abstract class,true
is returned. Otherwise,false
is returned.
func isOpen()
public func isOpen(): Bool
Description: Checks whether the class
type corresponding to ClassTypeInfo has the open
semantics.
Note:
It is not necessary that only the
class
type modified by theopen
modifier has theopen
semantics. For example,abstract class
has theopen
semantics no matter whether it is modified by theopen
modifier.
Returns:
- Bool: If the
class
type corresponding to ClassTypeInfo has theopen
semantics,true
is returned. Otherwise,false
is returned.
func isSealed()
public func isSealed(): Bool
Description: Checks whether the class
type corresponding to ClassTypeInfo has the sealed
semantics.
Returns:
- Bool: If the
class
type corresponding to ClassTypeInfo has thesealed
semantics,true
is returned. Otherwise,false
is returned.
class ConstructorInfo
public class ConstructorInfo <: Equatable<ConstructorInfo> & Hashable & ToString
Description: Describes constructor information.
Parent Type:
prop annotations
public prop annotations: Collection<Annotation>
Description: Obtains all annotations applied to the constructors corresponding to ConstructorInfo and returns the corresponding collection.
Note:
- If no annotation is applied to the constructors corresponding to the constructor information, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
Type: Collection<Annotation>
prop parameters
public prop parameters: InfoList<ParameterInfo>
Description: Obtains the formal parameter type list of the constructor corresponding to ConstructorInfo.
Type: InfoList<ParameterInfo>
func apply(Array<Any>)
public func apply(args: Array<Any>): Any
Description: Calls the constructor corresponding to ConstructorInfo, passes the actual parameter list, and returns the call result.
Note:
- Currently, an actual parameter cannot be an instance of the
struct
type.- Currently, constructors defined in a
struct
type cannot be called.
Parameters:
Returns:
- Any: type instance constructed by the constructor
Throws:
- InvocationTargetException: If the constructor corresponding to the constructor information belongs to an abstract class, this exception is thrown.
- IllegalArgumentException: If the number of actual parameters in the actual parameter list
args
is not equal to that of formal parameters in the formal parameter list of the constructor corresponding to the constructor information, this exception is thrown. - IllegalTypeException: If the runtime type of any actual parameter in the actual parameter list
args
is not a subtype of the declaring type of the corresponding formal parameters of the constructor corresponding to the constructor information, this exception is thrown. - Exception: If an exception is thrown inside the constructor corresponding to the called constructor information, the exception is encapsulated as Exception and thrown.
func findAnnotation<T>() where T <: Annotation
public func findAnnotation<T>(): Option<T> where T <: Annotation
Description: Attempts to obtain the annotation that is applied to the constructors corresponding to ConstructorInfo and has a given qualified name.
Returns:
- Option<T>: If a match is found, the annotation is returned. Otherwise,
None
is returned.
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the constructor information.
Returns:
- Int64: hash value of the constructor information
func toString()
public func toString(): String
Description: Obtains the constructor information in string format.
Returns:
- String: constructor information in string format
operator func !=(ConstructorInfo)
public operator func !=(that: ConstructorInfo): Bool
Description: Checks whether the constructor information is not equal to given constructor information.
Parameters:
- that: ConstructorInfo: other constructor information that is compared for equality
Returns:
- Bool: If the constructor information is not equal to
that
,true
is returned. Otherwise,false
is returned.
operator func ==(ConstructorInfo)
public operator func ==(that: ConstructorInfo): Bool
Description: Checks whether the constructor information is equal to given constructor information.
Parameters:
- that: ConstructorInfo: other constructor information that is compared for equality
Returns:
- Bool: If the constructor information is equal to
that
,true
is returned. Otherwise,false
is returned.
class GlobalFunctionInfo
public class GlobalFunctionInfo <: Equatable<GlobalFunctionInfo> & Hashable & ToString
Description: Describes global function information.
Parent Type:
prop name
public prop name: String
Description: Obtains the name of the global function corresponding to GlobalFunctionInfo.
Note:
All global functions that make up an overloading have the same name.
Type: String
prop parameters
public prop parameters: InfoList<ParameterInfo>
Description: Obtains the formal parameter information list of the global function corresponding to GlobalFunctionInfo.
Type: InfoList<ParameterInfo>
prop returnType
public prop returnType: TypeInfo
Description: Obtains the return type information of the global function corresponding to GlobalFunctionInfo.
Type: TypeInfo
func apply(Array<Any>)
public func apply(args: Array<Any>): Any
Description: Calls the global function corresponding to GlobalFunctionInfo, passes the actual parameter list, and returns the call result.
Note:
Currently, an actual parameter cannot be an instance of the
struct
type.
Parameters:
Returns:
- Any: call result of the global function
Throws:
- IllegalArgumentException: If the number of actual parameters in the actual parameter list
args
is not equal to that of formal parameters in the formal parameter list of the global function corresponding to the global function information, this exception is thrown. - IllegalTypeException: If the runtime type of any actual parameter in the actual parameter list
args
is not a subtype of the declaring type of the corresponding formal parameters of the global function corresponding to the global function information, this exception is thrown. - Exception: If an exception is thrown inside the global function corresponding to the called global function information, the exception is encapsulated as Exception and thrown.
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the global function information.
Returns:
- Int64: hash value of the global function information
func toString()
public func toString(): String
Description: Obtains the global function information in string format.
Returns:
- String: global function information in string format
operator func ==(GlobalFunctionInfo)
public operator func ==(that: GlobalFunctionInfo): Bool
Description: Checks whether the global function information is equal to given global function information.
Parameters:
- that: GlobalFunctionInfo: other global function information that is compared for equality
Returns:
- Bool: If the global function information is equal to
that
,true
is returned. Otherwise,false
is returned.
operator func !=(GlobalFunctionInfo)
public operator func !=(that: GlobalFunctionInfo): Bool
Description: Checks whether the global function information is not equal to given global function information.
Parameters:
- that: GlobalFunctionInfo: other global function information that is compared for equality
Returns:
- Bool: If the global function information is not equal to
that
,true
is returned. Otherwise,false
is returned.
class GlobalVariableInfo
public class GlobalVariableInfo <: Equatable<GlobalVariableInfo> & Hashable & ToString
Description: Describes global variable information.
Parent Type:
prop name
public prop name: String
Description: Obtains the name of the global variable corresponding to GlobalVariableInfo.
Type: String
prop typeInfo
public prop typeInfo: TypeInfo
Description: Obtains the declaring type information of the global variable corresponding to GlobalVariableInfo.
Type: TypeInfo
func getValue()
public func getValue(): Any
Description: Obtains the value of the global variable corresponding to GlobalVariableInfo.
Returns:
- Any: value of the global variable
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the global variable information.
Returns:
- Int64: hash value of the global variable information
func isMutable()
public func isMutable(): Bool
Description: Checks whether the global variables corresponding to GlobalVariableInfo can be modified.
Note:
- If an instance variable is modified by the
var
modifier, the global variable can be modified.- If an instance variable is modified by the
let
modifier, the global variable cannot be modified.- Any global variable whose type is
struct
cannot be modified.
Returns:
- Bool: If the global variable can be modified,
true
is returned. Otherwise,false
is returned.
func setValue(Any)
public func setValue(newValue: Any): Unit
Description: Sets the value of the global variable corresponding to GlobalVariableInfo.
Parameters:
- newValue: Any: new value
Throws:
- IllegalSetException: If the global variable corresponding to the global variable information cannot be modified, this exception is thrown.
- IllegalTypeException: If the runtime type of
newValue
is not a subtype of the declaring type of the global variable corresponding to the global variable information, this exception is thrown.
func toString()
public func toString(): String
Description: Obtains the global variable information in string format.
Returns:
- String: global variable information in string format
operator func ==(GlobalVariableInfo)
public operator func ==(that: GlobalVariableInfo): Bool
Description: Checks whether the global variable information is equal to given global variable information.
Parameters:
- that: GlobalVariableInfo: other global variable information that is compared for equality
Returns:
- Bool: If the global variable information is equal to
that
,true
is returned. Otherwise,false
is returned.
operator func !=(GlobalVariableInfo)
public operator func !=(that: GlobalVariableInfo): Bool
Description: Checks whether the global variable information is not equal to given global variable information.
Parameters:
- that: GlobalVariableInfo: other global variable information that is compared for equality
Returns:
- Bool: If the global variable information is not equal to
that
,true
is returned. Otherwise,false
is returned.
class InfoList
public class InfoList<T> <: Collection<T>
Description: Specifies an information list, which saves read-only reflection information.
Parent Type:
- Collection<T>
prop size
public prop size: Int64
Description: Obtains the number of elements in the information list.
Type: Int64
func get(Int64)
public func get(index: Int64): ?T
Description: Attempts to obtain the element at a specified location in the information list.
Parameters:
- index: Int64: location index
Returns:
- ?T: element at the specified location in the information list
func isEmpty()
public func isEmpty(): Bool
Description: Checks whether the information list is empty.
Returns:
- Bool: If the information list is empty,
true
is returned. Otherwise,false
is returned.
func iterator()
public func iterator(): Iterator<T>
Description: Obtains the iterator of the information list.
Returns:
- Iterator<T>: iterator of the information list
operator func [](Int64)
public operator func [](index: Int64): T
Description: Obtains the element at a specified location in the information list.
Parameters:
- index: Int64: location index
Returns:
- T: element at the specified location in the information list
Throws:
- IndexOutOfBoundsException: If
index
is out of range, this exception is thrown.
class InstanceFunctionInfo
public class InstanceFunctionInfo <: Equatable<InstanceFunctionInfo> & Hashable & ToString
Description: Describes instance function information.
Parent Type:
prop annotations
public prop annotations: Collection<Annotation>
Description: Obtains all annotations applied to the instance functions corresponding to InstanceFunctionInfo and returns the corresponding collection.
Note:
- If no annotation is applied to the instance functions corresponding to the instance function information, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
Type: Collection<Annotation>
prop modifiers
public prop modifiers: Collection<ModifierInfo>
Description: Obtains information about all modifiers of the instance function corresponding to InstanceFunctionInfo and returns the corresponding collection.
Note:
- If no modifier information is found, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
- Information about a modifier, whether present or not, is included in the collection as long as the modifier semantics is used.
Type: Collection<ModifierInfo>
prop name
public prop name: String
Description: Obtains the name of the instance function corresponding to InstanceFunctionInfo.
Note:
- All instance functions that make up an overloading have the same name.
- The name of an operator overloading function is the symbol of the operator itself, for example, "
+
", "*
", and "[]
".
Type: String
prop parameters
public prop parameters: InfoList<ParameterInfo>
Description: Obtains the formal parameter information list of the instance function corresponding to InstanceFunctionInfo.
Type: InfoList<ParameterInfo>
prop returnType
public prop returnType: TypeInfo
Description: Obtains the return value type information of the instance function corresponding to InstanceFunctionInfo.
Type: TypeInfo
func apply(Any, Array<Any>)
public func apply(instance: Any, args: Array<Any>): Any
Description: Calls the instance function corresponding to InstanceFunctionInfo, specifies an instance, passes the actual parameter list, and returns the call result.
Note:
- Currently,
instance
cannot be an instance of thestruct
type.- Currently, an actual parameter cannot be an instance of the
struct
type.
Parameters:
Returns:
- Any: call result of the instance function
Throws:
- InvocationTargetException: If the instance function corresponding to the instance function information is abstract, this exception is thrown.
- IllegalTypeException: If the runtime type of
instance
is not strictly equal to the type of the instance function corresponding to the instance function information, this exception is thrown. - IllegalArgumentException: If the number of actual parameters in the actual parameter list
args
is not equal to that of formal parameters in the formal parameter list of the instance function corresponding to the instance function information, this exception is thrown. - IllegalTypeException: If the runtime type of any actual parameter in the actual parameter list
args
is not a subtype of the declaring type of the corresponding formal parameters of the instance function corresponding to the instance function information, this exception is thrown. - Exception: If an exception is thrown inside the instance function corresponding to the called instance function information, the exception is encapsulated as Exception and thrown.
func findAnnotation<T>() where T <: Annotation
public func findAnnotation<T>(): Option<T> where T <: Annotation
Description: Attempts to obtain the annotation that is applied to the instance functions corresponding to InstanceFunctionInfo and has a given qualified name.
Returns:
- Option<T>: If a match is found, the annotation is returned. Otherwise,
None
is returned.
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the instance function information.
Returns:
- Int64: hash value of the instance function information
func isAbstract()
public func isAbstract(): Bool
Description: Checks whether the instance function corresponding to InstanceFunctionInfo has the abstract
semantics.
Returns:
- Bool: If the instance function has the
abstract
semantics,true
is returned. Otherwise,false
is returned.
func isOpen()
public func isOpen(): Bool
Description: Checks whether the instance function corresponding to InstanceFunctionInfo has the open
semantics.
Returns:
- Bool: If the instance function has the
open
semantics,true
is returned. Otherwise,false
is returned.
Note:
By default, instance functions of the
interface
type have theopen
semantics.
func toString()
public func toString(): String
Description: Obtains the instance function information in string format.
Returns:
- String: instance function information in string format
operator func ==(InstanceFunctionInfo)
public operator func ==(that: InstanceFunctionInfo): Bool
Description: Checks whether the instance function information is equal to given instance function information.
Parameters:
- that: InstanceFunctionInfo: other instance function information that is compared for equality
Returns:
- Bool: If the instance function information is equal to
that
,true
is returned. Otherwise,false
is returned.
operator func !=(InstanceFunctionInfo)
public operator func !=(that: InstanceFunctionInfo): Bool
Description: Checks whether the instance function information is not equal to given instance function information.
Parameters:
- that: InstanceFunctionInfo: other instance function information that is compared for equality
Returns:
- Bool: If the instance function information is not equal to
that
,true
is returned. Otherwise,false
is returned.
class InstancePropertyInfo
public class InstancePropertyInfo <: Equatable<InstancePropertyInfo> & Hashable & ToString
Description: Describes instance property information.
Parent Type:
prop annotations
public prop annotations: Collection<Annotation>
Description: Obtains all annotations applied to the instance properties corresponding to InstancePropertyInfo and returns the corresponding collection.
Note:
- If no annotation is applied to the instance properties corresponding to the instance property information, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
Type: Collection<Annotation>
prop modifiers
public prop modifiers: Collection<ModifierInfo>
Description: Obtains information about all modifiers of the instance property corresponding to InstancePropertyInfo and returns the corresponding collection.
Note:
- If the instance property is not modified by any modifiers, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
- Information about a modifier, whether present or not, is included in the collection as long as the modifier semantics is used.
Type: Collection<ModifierInfo>
prop name
public prop name: String
Description: Obtains the name of the instance property corresponding to InstancePropertyInfo.
Type: String
prop typeInfo
public prop typeInfo: TypeInfo
Description: Obtains the declaring type information of the instance property corresponding to InstancePropertyInfo.
Type: TypeInfo
func findAnnotation<T>() where T <: Annotation
public func findAnnotation<T>(): Option<T> where T <: Annotation
Description: Attempts to obtain the annotation that is applied to the instance properties corresponding to InstancePropertyInfo and has a given qualified name.
Returns:
- Option<T>: If a match is found, the annotation is returned. Otherwise,
None
is returned.
func getValue(Any)
public func getValue(instance: Any): Any
Description: Obtains the value of the instance property corresponding to InstancePropertyInfo in a specified instance.
Note:
Currently,
instance
cannot be an instance of thestruct
type.
Parameters:
- instance: Any: instance
Returns:
- Any: value of the instance property in
instance
Throws:
- IllegalTypeException: If the runtime type of
instance
is not strictly equal to the type of the instance property corresponding to the instance property information, this exception is thrown.
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the instance property information.
Returns:
- Int64: hash value of the instance property information
func isMutable()
public func isMutable(): Bool
Description: Checks whether the instance properties corresponding to InstancePropertyInfo can be modified.
Note:
- If an instance property is modified by the
mut
modifier, it can be modified. Otherwise, it cannot be modified.- Any instance property of an instance belonging to any
struct
type cannot be modified.- Any instance property whose type is
struct
cannot be modified.
Returns:
- Bool: If the instance properties corresponding to the instance property information can be modified,
true
is returned. Otherwise,false
is returned.
func setValue(Any, Any)
public func setValue(instance: Any, newValue: Any): Unit
Description: Sets the value of the instance property corresponding to InstancePropertyInfo in a specified instance.
Note:
Currently,
instance
cannot be an instance of thestruct
type.
Parameters:
Throws:
- IllegalSetException: If the instance property corresponding to the instance property information cannot be modified, this exception is thrown.
- IllegalTypeException: If the runtime type of
instance
is not strictly equal to the type of the instance property corresponding to the instance property information, this exception is thrown. - IllegalTypeException: If the runtime type of
newValue
is not a subtype of the declaring type of the instance property corresponding to the instance property information, this exception is thrown.
func toString()
public func toString(): String
Description: Obtains the instance property information in string format.
Returns:
- String: instance property information in string format
operator func !=(InstancePropertyInfo)
public operator func !=(that: InstancePropertyInfo): Bool
Description: Checks whether the instance property information is not equal to given instance property information.
Parameters:
- that: InstancePropertyInfo: other instance property information that is compared for equality
Returns:
- Bool: If the instance property information is not equal to
that
,true
is returned. Otherwise,false
is returned.
operator func ==(InstancePropertyInfo)
public operator func ==(that: InstancePropertyInfo): Bool
Description: Checks whether the instance property information is equal to given instance property information.
Parameters:
- that: InstancePropertyInfo: other instance property information that is compared for equality
Returns:
- Bool: If the instance property information is equal to
that
,true
is returned. Otherwise,false
is returned.
class InstanceVariableInfo
public class InstanceVariableInfo <: Equatable<InstanceVariableInfo> & Hashable & ToString
Description: Describes instance variable information.
Parent Type:
prop annotations
public prop annotations: Collection<Annotation>
Description: Obtains all annotations applied to the instance variables corresponding to InstanceVariableInfo and returns the corresponding collection.
Note:
- If no annotation is applied to the instance variables corresponding to the instance variable information, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
Type: Collection<Annotation>
prop modifiers
public prop modifiers: Collection<ModifierInfo>
Description: Obtains information about all modifiers of the instance variable corresponding to InstanceVariableInfo and returns the corresponding collection.
Note:
- If no modifier information is found, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
- Information about a modifier, whether present or not, is included in the collection as long as the modifier semantics is used.
Type: Collection<ModifierInfo>
prop name
public prop name: String
Description: Obtains the name of the instance variable corresponding to InstanceVariableInfo.
Type: String
prop typeInfo
public prop typeInfo: TypeInfo
Description: Obtains the declaring type information of the instance variable corresponding to InstanceVariableInfo.
Type: TypeInfo
func findAnnotation<T>() where T <: Annotation
public func findAnnotation<T>(): Option<T> where T <: Annotation
Description: Attempts to obtain the annotation that is applied to the instance variables corresponding to InstanceVariableInfo and has a given qualified name.
Returns:
- Option<T>: If a match is found, the annotation is returned. Otherwise,
None
is returned.
func getValue(Any)
public func getValue(instance: Any): Any
Description: Obtains the value of the instance variable corresponding to InstanceVariableInfo in a specified instance.
Note:
- Currently,
instance
cannot be an instance of thestruct
type.- Currently, the return value cannot be an instance of the
struct
type.
Parameters:
- instance: Any: instance
Returns:
- Any: value of the instance variable in
instance
Throws:
- IllegalTypeException: If the runtime type of
instance
is not strictly equal to the type of the instance variable corresponding to the instance variable information, this exception is thrown.
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the instance variable information.
Returns:
- Int64: hash value of the instance variable information
func isMutable()
public func isMutable(): Bool
Description: Checks whether the instance variables corresponding to InstanceVariableInfo can be modified.
Note:
- An instance variable modified by the
var
modifier can be modified.- An instance variable modified by the
let
modifier cannot be modified.- Any instance variable of an instance belonging to any
struct
type cannot be modified.- Any instance variable whose type is
struct
cannot be modified.
Returns:
- Bool: If the instance variables corresponding to the instance variable information can be modified,
true
is returned. Otherwise,false
is returned.
func setValue(Any, Any)
public func setValue(instance: Any, newValue: Any): Unit
Description: Sets the value of the instance variable corresponding to InstanceVariableInfo in a specified instance.
Note:
Currently,
instance
cannot be an instance of thestruct
type.
Parameters:
Throws:
- IllegalSetException: If the instance variable corresponding to the instance variable information cannot be modified, this exception is thrown.
- IllegalTypeException: If the runtime type of
instance
is not strictly equal to the type of the instance variable corresponding to the instance variable information, this exception is thrown. - IllegalTypeException: If the runtime type of
newValue
is not a subtype of the declaring type of the instance variables corresponding to the instance variable information, this exception is thrown.
func toString()
public func toString(): String
Description: Obtains the instance variable information in string format.
Returns:
- String: instance variable information in string format
operator func ==(InstanceVariableInfo)
public operator func ==(that: InstanceVariableInfo): Bool
Description: Checks whether the instance variable information is equal to given instance variable information.
Parameters:
- that: InstanceVariableInfo: other instance variable information that is compared for equality
Returns:
- Bool: If the instance variable information is equal to
that
,true
is returned. Otherwise,false
is returned.
operator func !=(InstanceVariableInfo)
public operator func !=(that: InstanceVariableInfo): Bool
Description: Checks whether the instance variable information is not equal to given instance variable information.
Parameters:
- that: InstanceVariableInfo: other instance variable information that is compared for equality
Returns:
- Bool: If the instance variable information is not equal to
that
,true
is returned. Otherwise,false
is returned.
class InterfaceTypeInfo
public class InterfaceTypeInfo <: TypeInfo
Description: Specifies the interface
type information.
Parent Type:
prop sealedSubtypes
public prop sealedSubtypes: Collection<TypeInfo>
Description: Obtains the type information of all subtypes in the package to which the interface
type belongs and returns the corresponding collection if the interface
type corresponding to InterfaceTypeInfo has the sealed
semantics.
Note:
- If the
interface
type does not have thesealed
semantics, an empty collection is returned.- If the
interface
type has thesealed
semantics, the obtained collection cannot be an empty collection because theinterface
type itself is its own subtype.
Type: Collection<TypeInfo>
func isSealed()
public func isSealed(): Bool
Description: Checks whether the interface
type corresponding to InterfaceTypeInfo has the sealed
semantics.
Returns:
- Bool: If the
interface
type has thesealed
semantics,true
is returned. Otherwise,false
is returned.
class ModuleInfo
public class ModuleInfo <: Equatable<ModuleInfo> & Hashable & ToString
Description: Describes module information and provides the capabilities of loading and caching Cangjie dynamic modules and querying package information inside the modules.
A Cangjie dynamic module is a special binary file generated by the Cangjie compiler. Such file can be loaded and used by an external Cangjie program at runtime.
Cangjie dynamic library modules exist in shared library (.so
file), dynamic link library (.dll
file), and other file formats in different operating systems.
Note:
A module cannot contain packages with the same qualified name.
Parent Type:
prop name
public prop name: String
Description: Obtains the name of the module corresponding to ModuleInfo.
Note:
- A module name is determined by the file name of the loaded module. The format of the file name is
lib<module_name>_<package_name>(.<package_name>)*
.<module_name>
and<package_name>
cannot be empty.- Due to the limitations of the current implementation, if
<module_name>
contains an underscore "_
", unexpected loading errors may occur.
Type: String
prop packages
public prop packages: Collection<PackageInfo>
Description: Obtains all packages contained in the module.
Type: Collection<PackageInfo>
prop version
public prop version: String
Description: Obtains the version number of the module corresponding to ModuleInfo.
Note:
Currently, there is no version information in the dynamic library. Therefore, the obtained version number is always
1.0
.
Type: String
static func find(String)
public static func find(moduleName: String): Option<ModuleInfo>
Description: Attempts to obtain information about the module that matches a given module name from all loaded Cangjie dynamic library modules.
Parameters:
- moduleName: String: Cangjie dynamic library module name
Returns:
- Option<ModuleInfo>: If a match is found, information about the module is returned. Otherwise,
None
is returned.
static func load(String)
public static func load(path: String): ModuleInfo
Description: Dynamically loads a Cangjie dynamic library module in a specified path and obtains information about the module at runtime.
Notes:
- To improve compatibility, the shared library file name in
path
does not contain an extension (such as.so
and.dll
).- Due to the limitations of the current implementation, dynamic libraries with the same module name cannot be loaded at the same time. Otherwise, an exception is thrown. For example, the loading of the shared libraries corresponding to packages
m/a
,m/a.b
, andm/a.c
is mutually exclusive.
Parameters:
- path: String: absolute or relative path of the shared library file
Throws:
- ReflectException: If the shared library fails to be loaded, this exception is thrown.
- UnsupportedException: If shared libraries with the same module name are loaded repeatedly, this exception is thrown.
func getPackageInfo(String)
public func getPackageInfo(packageName: String): PackageInfo
Description: Attempts to obtain information about the package that matches the name or qualified name of a given package in the module corresponding to ModuleInfo.
Parameters:
- packageName: String: name or qualified name of the package
Returns:
- PackageInfo: If a match is found, information about the package is returned.
Throws:
- InfoNotFoundException: If no matched package is found, this exception is thrown.
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the module information.
Returns:
- Int64: hash value of the module information
Note:
The internal implementation is the hash value of the string consisting of the name and version number of the module information.
func toString()
public func toString(): String
Description: Obtains the module information in string format.
Returns:
- String: module information in string format
Note:
The content is the name and version number of the module.
operator func !=(ModuleInfo)
public operator func !=(that: ModuleInfo): Bool
Description: Checks whether the module information is not equal to given module information.
Parameters:
- that: ModuleInfo: other module information that is compared for equality
Returns:
- Bool: If the module information is not equal to
that
,true
is returned. Otherwise,false
is returned.
operator func ==(ModuleInfo)
public operator func ==(that: ModuleInfo): Bool
Description: Checks whether the module information is equal to given module information.
Parameters:
- that: ModuleInfo: other module information that is compared for equality
Returns:
- Bool: If the module information is equal to
that
,true
is returned. Otherwise,false
is returned.
class PackageInfo
public class PackageInfo <: Equatable<PackageInfo> & Hashable & ToString
Description: Describes package information.
Parent Type:
prop functions
public prop functions: Collection<GlobalFunctionInfo>
Description: Obtains the list consisting of information about all public global functions in the package corresponding to PackageInfo.
Type: Collection<GlobalFunctionInfo>
prop name
public prop name: String
Description: Obtains the name of the package corresponding to the package information.
Note:
A package name does not contain the name of the module where the package is located or the name of its parent package. For example, the name of the package with the qualified name
a/b.c.d
isd
.
Type: String
prop qualifiedName
public prop qualifiedName: String
Description: Obtains the qualified name of the package corresponding to PackageInfo.
Note:
The qualified name of a package is in the format of
(module_name/)?(default|package_name)(.package_name)*
. For example, the package with the qualified namea/b.c.d
is in packagec
in packageb
under modulea
.
Type: String
prop typeInfos
public prop typeInfos: Collection<TypeInfo>
Description: Obtains the type information of all globally defined public types in the package corresponding to PackageInfo and returns the corresponding collection.
Note:
Currently, the list does not contain all types that cannot be reflected.
Type: Collection<TypeInfo>
prop variables
public prop variables: Collection<GlobalVariableInfo>
Description: Obtains the list consisting of information about all public global variables in the package corresponding to PackageInfo.
Type: Collection<GlobalVariableInfo>
func getFunction(String, Array<TypeInfo>)
public func getFunction(name: String, parameterTypes: Array<TypeInfo>): GlobalFunctionInfo
Description: Attempts to obtain information about a public global function with a given function name and matching the given formal parameter type information list from the package corresponding to PackageInfo.
Parameters:
- name: String: global function name
- parameterTypes: Array<TypeInfo>: formal parameter type information list
Throws:
- InfoNotFoundException: If no matched globally defined public global function is found, this exception is thrown.
func getTypeInfo(String)
public func getTypeInfo(qualifiedName: String): TypeInfo
Description: Attempts to obtain the type information of the globally defined public type with a given type name from the package corresponding to PackageInfo.
Parameters:
- qualifiedName: String: qualified name of the type
Returns:
- TypeInfo: If a match is found, the type information of the globally defined public type is returned.
Throws:
- InfoNotFoundException: If no matched globally defined public type is found, this exception is thrown.
func getVariable(String)
public func getVariable(name: String): GlobalVariableInfo
Description: Attempts to obtain information about a public global variable with a given variable name from the package corresponding to PackageInfo.
Parameters:
- name: String: global variable name
Throws:
- InfoNotFoundException: If no matched globally defined public global variable is found, this exception is thrown.
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the package information.
Returns:
- Int64: hash value of the package information
func toString()
public func toString(): String
Description: Obtains the package information in string format.
Note:
The internal implementation is the qualified name string of the package information.
Returns:
- String: package information in string format
operator func !=(PackageInfo)
public operator func !=(that: PackageInfo): Bool
Description: Checks whether the package information is not equal to given package information.
Note:
The internal implementation is to compare whether two package information qualified names are equal.
Parameters:
- that: PackageInfo: other package information that is compared for equality
Returns:
- Bool: If the package information is not equal to
that
,true
is returned. Otherwise,false
is returned.
operator func ==(PackageInfo)
public operator func ==(that: PackageInfo): Bool
Description: Checks whether the package information is equal to given package information.
Note:
The internal implementation is to compare whether two package information qualified names are equal.
Parameters:
- that: PackageInfo: other package information that is compared for equality
Returns:
- Bool: If the package information is equal to
that
,true
is returned. Otherwise,false
is returned.
class ParameterInfo
public class ParameterInfo <: Equatable<ParameterInfo> & Hashable & ToString
Description: Describes formal parameter information of a function.
Parent Type:
prop annotations
public prop annotations: Collection<Annotation>
Description: Obtains all annotations applied to the formal parameters of the function corresponding to ParameterInfo and returns the corresponding collection.
Note:
- If no annotation is applied to the formal parameters of the function corresponding to the function formal parameter information, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
Type: Collection<Annotation>
prop index
public prop index: Int64
Description: Obtains the sequence number of the formal parameter corresponding to ParameterInfo in the function.
Note:
index
starts from 0.
Type: Int64
prop name
public prop name: String
Description: Obtains the name of the formal parameter corresponding to ParameterInfo.
Type: String
prop typeInfo
public prop typeInfo: TypeInfo
Description: Obtains the declaring type information of the formal parameters of the function corresponding to ParameterInfo.
Type: TypeInfo
func findAnnotation<T>() where T <: Annotation
public func findAnnotation<T>(): Option<T> where T <: Annotation
Description: Attempts to obtain the annotation that is applied to the formal parameters of the function corresponding to ParameterInfo and has a given qualified name.
Returns:
- Option<T>: If a match is found, the annotation is returned. Otherwise,
None
is returned.
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the formal parameter information of the function.
Returns:
- Int64: hash value of the formal parameter information of the function
func toString()
public func toString(): String
Description: Obtains the formal parameter information of the function in string format.
Returns:
- String: formal parameter information of the function in string format
operator func !=(ParameterInfo)
public operator func !=(that: ParameterInfo): Bool
Description: Checks whether the formal parameter information of the function is not equal to that of a given function.
Parameters:
- that: ParameterInfo: formal parameter information of another function that is compared for equality
Returns:
- Bool: If the formal parameter information of the function is not equal to
that
,true
is returned. Otherwise,false
is returned.
operator func ==(ParameterInfo)
public operator func ==(that: ParameterInfo): Bool
Description: Checks whether the formal parameter information of the function is equal to that of a given function.
Parameters:
- that: ParameterInfo: formal parameter information of another function that is compared for equality
Returns:
- Bool: If the formal parameter information of the function is equal to
that
,true
is returned. Otherwise,false
is returned.
class PrimitiveTypeInfo
public class PrimitiveTypeInfo <: TypeInfo
Description: Describes type information of a primitive data type.
Primitive data types include untyped (Nothing
), unit (Unit), character (Rune), Boolean (Bool), integer (Int8, Int16, Int32, Int64, IntNative, UInt8, UInt16, UInt32, UInt64, UIntNative), and floating point (Float16, Float32, Float64) types.
Note:
Currently, the
Nothing
primitive data type is not supported.
Parent Type:
class StaticFunctionInfo
public class StaticFunctionInfo <: Equatable<StaticFunctionInfo> & Hashable & ToString
Description: Describes static member function information.
Parent Type:
prop annotations
public prop annotations: Collection<Annotation>
Description: Obtains all annotations applied to the static member functions corresponding to StaticFunctionInfo and returns the corresponding collection.
Note:
- If no annotation is applied to the static member functions corresponding to StaticFunctionInfo, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
Type: Collection<Annotation>
prop modifiers
public prop modifiers: Collection<ModifierInfo>
Description: Obtains information about all modifiers of the static member function corresponding to StaticFunctionInfo and returns the corresponding collection.
Note:
- If the static member function is not modified by any modifiers, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
- Information about a modifier, whether present or not, is included in the collection as long as the modifier semantics is used.
Type: Collection<ModifierInfo>
prop name
public prop name: String
Description: Obtains the name of the static member function corresponding to StaticFunctionInfo.
Note:
All static member functions that make up an overloading have the same name.
Type: String
prop parameters
public prop parameters: InfoList<ParameterInfo>
Description: Obtains the formal parameter information list of the static member function corresponding to StaticFunctionInfo.
Type: InfoList<ParameterInfo>
prop returnType
public prop returnType: TypeInfo
Description: Obtains the return value type information of the static member function corresponding to StaticFunctionInfo.
Type: TypeInfo
func apply(Array<Any>)
public func apply(args: Array<Any>): Any
Description: Calls the static member function corresponding to StaticFunctionInfo, passes the actual parameter list, and returns the call result.
Note:
Currently, an actual parameter cannot be an instance of the
struct
type.
Parameters:
Returns:
- Any: call result of the static member function
Throws:
- IllegalArgumentException: If the number of actual parameters in the actual parameter list
args
is not equal to that of formal parameters in the formal parameter list of the static member function corresponding to the static member function information, this exception is thrown. - IllegalTypeException: If the runtime type of any actual parameter in the actual parameter list
args
is not a subtype of the declaring type of the corresponding formal parameters of the static member function corresponding to the static member function information, this exception is thrown. - Exception: If an exception is thrown inside the static member function corresponding to the called static member function information, the exception is encapsulated as Exception and thrown.
func findAnnotation<T>() where T <: Annotation
public func findAnnotation<T>(): Option<T> where T <: Annotation
Description: Attempts to obtain the annotation that is applied to the static member functions corresponding to StaticFunctionInfo and has a given qualified name.
Returns:
- Option<T>: If a match is found, the annotation is returned. Otherwise,
None
is returned.
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the static member function information.
Returns:
- Int64: hash value of the static member function information
func toString()
public func toString(): String
Description: Obtains the static member function information in string format.
Returns:
- String: static member function information in string format
operator func !=(StaticFunctionInfo)
public operator func !=(that: StaticFunctionInfo): Bool
Description: Checks whether the static member function information is not equal to given static member function information.
Parameters:
- that: StaticFunctionInfo: other static member function information that is compared for equality
Returns:
- Bool: If the static member function information is not equal to
that
,true
is returned. Otherwise,false
is returned.
operator func ==(StaticFunctionInfo)
public operator func ==(that: StaticFunctionInfo): Bool
Description: Checks whether the static member function information is equal to given static member function information.
Parameters:
- that: StaticFunctionInfo: other static member function information that is compared for equality
Returns:
- Bool: If the static member function information is equal to
that
,true
is returned. Otherwise,false
is returned.
class StaticPropertyInfo
public class StaticPropertyInfo <: Equatable<StaticPropertyInfo> & Hashable & ToString
Description: Specifies the static member property information.
Parent Type:
prop annotations
public prop annotations: Collection<Annotation>
Description: Obtains the collection of all annotations applied to the static member properties corresponding to StaticPropertyInfo.
Note:
- If no annotation is applied to the static member properties corresponding to the static member property information, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
Type: Collection<Annotation>
prop modifiers
public prop modifiers: Collection<ModifierInfo>
Description: Obtains information about all modifiers of the static member property corresponding to StaticPropertyInfo and returns the corresponding collection.
Note:
- If the static member property is not modified by any modifiers, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
- Currently, the content of the obtained modifier collection is disordered and has not been unified.
Type: Collection<ModifierInfo>
prop name
public prop name: String
Description: Obtains the name of the static member property corresponding to StaticPropertyInfo.
Type: String
prop typeInfo
public prop typeInfo: TypeInfo
Description: Obtains the declaring type information of the static member property corresponding to StaticPropertyInfo.
Type: TypeInfo
func findAnnotation<T>() where T <: Annotation
public func findAnnotation<T>(): Option<T> where T <: Annotation
Description: Attempts to obtain the annotation that is applied to the static member properties corresponding to StaticPropertyInfo and has a given qualified name.
Returns:
- Option<T>: If a match is found, the annotation is returned. Otherwise,
None
is returned.
func getValue()
public func getValue(): Any
Description: Obtains the value of the static member property corresponding to StaticPropertyInfo.
Note:
If the static member property lacks a valid implementation, for example, the abstract static member property of the
interface
type, UnsupportedException should be thrown. However, this has not been implemented yet due to the lack of support by the backend.
Returns:
- Any: value of the static member property
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the static member property information.
Returns:
- Int64: hash value of the static member property information
func isMutable()
public func isMutable(): Bool
Description: Checks whether the static member properties corresponding to the static member property information can be modified.
Returns:
- Bool: If the static member properties corresponding to the static member property information can be modified,
true
is returned. Otherwise,false
is returned.
Note:
- If a static member property is modified by the
mut
modifier, it can be modified. Otherwise, it cannot be modified.- Any static member property belonging to any
struct
type cannot be modified.- Any static member property whose type is
struct
cannot be modified.
func setValue(Any)
public func setValue(newValue: Any): Unit
Description: Sets the value of the static member property corresponding to StaticPropertyInfo.
Note:
If the static member property lacks a valid implementation, for example, the abstract static member property of the
interface
type, UnsupportedException should be thrown. However, this has not been implemented yet due to the lack of support by the backend.
Parameters:
- newValue: Any: new value
Throws:
- IllegalSetException: If the static member property corresponding to the static member property information cannot be modified, this exception is thrown.
- IllegalTypeException: If the runtime type of
newValue
is not a subtype of the declaring type of the static member property corresponding to the static member property information, this exception is thrown.
func toString()
public func toString(): String
Description: Obtains the static member property information in string format.
Returns:
- String: static member property information in string format
operator func !=(StaticPropertyInfo)
public operator func !=(that: StaticPropertyInfo): Bool
Description: Checks whether the static member property information is not equal to given static member property information.
Parameters:
- that: StaticPropertyInfo: other static member property information that is compared for equality
Returns:
- Bool: If the static member property information is not equal to
that
,true
is returned. Otherwise,false
is returned.
operator func ==(StaticPropertyInfo)
public operator func ==(that: StaticPropertyInfo): Bool
Description: Checks whether the static member property information is equal to given static member property information.
Parameters:
- that: StaticPropertyInfo: other static member property information that is compared for equality
Returns:
- Bool: If the static member property information is equal to
that
,true
is returned. Otherwise,false
is returned.
class StaticVariableInfo
public class StaticVariableInfo <: Equatable<StaticVariableInfo> & Hashable & ToString
Description: Describes static member variable information.
Parent Type:
prop annotations
public prop annotations: Collection<Annotation>
Description: Obtains all annotations applied to the static member variables corresponding to StaticVariableInfo and returns the corresponding collection.
Note:
- If no annotation is applied to the static member variables corresponding to StaticVariableInfo, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
Type: Collection<Annotation>
prop modifiers
public prop modifiers: Collection<ModifierInfo>
Description: Obtains information about all modifiers of the static member variable corresponding to StaticVariableInfo and returns the corresponding collection.
Note:
- If the static member variable is not modified by any modifiers, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
- Currently, the content of the obtained modifier collection is disordered and has not been unified.
Type: Collection<ModifierInfo>
prop name
public prop name: String
Description: Obtains the name of the static member variable corresponding to StaticVariableInfo.
Type: String
prop typeInfo
public prop typeInfo: TypeInfo
Description: Obtains the declaring type information of the static member variables corresponding to StaticVariableInfo.
Type: TypeInfo
func findAnnotation<T>() where T <: Annotation
public func findAnnotation<T>(): Option<T> where T <: Annotation
Description: Attempts to obtain the annotation that is applied to the static member variables corresponding to StaticVariableInfo and has a given qualified name.
Returns:
- Option<T>: If a match is found, the annotation is returned. Otherwise,
None
is returned.
func getValue()
public func getValue(): Any
Description: Obtains the value of the static member variable corresponding to StaticVariableInfo.
Returns:
- Any: value of the static member variable
Note:
- The return value cannot be of the
struct
type.
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the static member variable information.
Returns:
- Int64: hash value of the static member variable information
func isMutable()
public func isMutable(): Bool
Description: Checks whether the static member variables corresponding to StaticVariableInfo can be modified.
Note:
- A static member variable modified by the
var
modifier can be modified.- A static member variable modified by the
let
modifier cannot be modified.- Any static member variable belonging to any
struct
type cannot be modified.- Any static member variable whose type is
struct
cannot be modified.
Returns:
- Bool: If the static member variables corresponding to the static member variable information can be modified,
true
is returned. Otherwise,false
is returned.
func setValue(Any)
public func setValue(newValue: Any): Unit
Description: Sets the value of the static member variable corresponding to StaticVariableInfo.
Parameters:
- newValue: Any: new value
Throws:
- IllegalSetException: If the static member variable corresponding to StaticVariableInfo cannot be modified, this exception is thrown.
- IllegalTypeException: If the runtime type of
newValue
is not a subtype of the declaring type of the static member variables corresponding to the static member variable information, this exception is thrown.
func toString()
public func toString(): String
Description: Obtains the static member variable information in string format.
Returns:
- String: static member variable information in string format
operator func !=(StaticVariableInfo)
public operator func !=(that: StaticVariableInfo): Bool
Description: Checks whether the static member variable information is not equal to given static member variable information.
Parameters:
- that: StaticVariableInfo: other static member variable information that is compared for equality
Returns:
- Bool: If the static member variable information is not equal to
that
,true
is returned. Otherwise,false
is returned.
operator func ==(StaticVariableInfo)
public operator func ==(that: StaticVariableInfo): Bool
Description: Checks whether the static member variable information is equal to given static member variable information.
Parameters:
- that: StaticVariableInfo: other static member variable information that is compared for equality
Returns:
- Bool: If the static member variable information is equal to
that
,true
is returned. Otherwise,false
is returned.
class StructTypeInfo
public class StructTypeInfo <: TypeInfo
Description: Describes type information of a struct
type.
Parent Type:
prop constructors
public prop constructors: Collection<ConstructorInfo>
Description: Obtains information about all public constructors of struct
corresponding to StructTypeInfo and returns the corresponding collection.
Note:
- If the
struct
type does not have any public constructor, an empty collection is returned.- The collection does not guarantee a constant traversal sequence.
Type: Collection<ConstructorInfo>
prop instanceVariables
public prop instanceVariables: Collection<InstanceVariableInfo>
Description: Obtains information about all public instance variables of struct
corresponding to StructTypeInfo and returns the corresponding collection.
Note:
- If the
struct
type does not have any public instance variable, an empty collection is returned.- The collection does not guarantee a constant traversal sequence.
Type: Collection<InstanceVariableInfo>
prop staticVariables
public prop staticVariables: Collection<StaticVariableInfo>
Description: Obtains information about all public static member variables of struct
corresponding to StructTypeInfo and returns the corresponding collection.
Note:
- If the
struct
type does not have any public static member variable, an empty collection is returned.- The collection does not guarantee a constant traversal sequence.
Type: Collection<StaticVariableInfo>
func construct(Array<Any>)
public func construct(args: Array<Any>): Any
Description: Searches for and calls the matched constructor based on an actual parameter list in the struct
type corresponding to StructTypeInfo, passes the actual parameter list, and returns the call result.
Parameters:
Returns:
- Any: instance of the
struct
type
Throws:
- MisMatchException: If
args
fails to match any public constructor of thestruct
type, this exception is thrown. - InvocationTargetException: Any exception thrown inside the called constructor is encapsulated as InvocationTargetException and thrown.
Note:
Since the
construct
function essentially calls theapply
function, currently, it cannot be used because a constructor defined in thestruct
type cannot call theapply
function.
func getConstructor(Array<TypeInfo>)
public func getConstructor(parameterTypes: Array<TypeInfo>): ConstructorInfo
Description: Attempts to obtain information about a public constructor that matches a given formal parameter type information list from the struct
type corresponding to StructTypeInfo.
Parameters:
Returns:
- ConstructorInfo: If a match is found, information about the public constructor is returned.
Throws:
- InfoNotFoundException: If no matched public constructor is found, this exception is thrown.
func getInstanceVariable(String)
public func getInstanceVariable(name: String): InstanceVariableInfo
Description: Attempts to obtain information about a matched instance variable in the struct
type corresponding to StructTypeInfo based on a given variable name.
Parameters:
- name: String: variable name
Returns:
- InstanceVariableInfo: If a match is found, information about the instance variable is returned.
Throws:
- InfoNotFoundException: If no matched public instance variable is found, this exception is thrown.
func getStaticVariable(String)
public func getStaticVariable(name: String): StaticVariableInfo
Description: Attempts to obtain information about a matched static member variable in the struct
type corresponding to StructTypeInfo based on a given variable name.
Parameters:
- name: String: variable name
Returns:
- StaticVariableInfo: If a match is found, information about the static member variable is returned.
Throws:
- InfoNotFoundException: If no matched public static member variable is found, this exception is thrown.
class TypeInfo
sealed abstract class TypeInfo <: Equatable<TypeInfo> & Hashable & ToString
Description: TypeInfo provides universal operation APIs for all data types. Developers can perform reflection operations without converting a data type to a more specific one, such as ClassTypeInfo.
Subtypes of TypeInfo include PrimitiveTypeInfo, StructTypeInfo, ClassTypeInfo, and InterfaceTypeInfo, which correspond to the basic, struct
, class
, and interface
data types, respectively.
Note
The qualified name of a type is
(module_name/)?(default|package_name)(.package_name)*.(type_name)
.
Parent Type:
prop annotations
public prop annotations: Collection<Annotation>
Description: Obtains all annotations applied to the types corresponding to TypeInfo and returns the corresponding collection.
Note:
- If no annotation is applied to the types corresponding to the type information, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
Type: Collection<Annotation>
prop instanceFunctions
public prop instanceFunctions: Collection<InstanceFunctionInfo>
Description: Obtains information about all public instance functions of the type corresponding to TypeInfo and returns the corresponding collection.
Note:
- If the type corresponding to TypeInfo does not have any public instance function, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
- If the type corresponding to the type information is
struct
orclass
, the collection contains information about non-abstract instance functions inherited from anotherinterface
type.
Type: Collection<InstanceFunctionInfo>
prop instanceProperties
public prop instanceProperties: Collection<InstancePropertyInfo>
Description: Obtains information about all public instance properties of the type corresponding to TypeInfo and returns the corresponding collection.
Note:
- If the type corresponding to TypeInfo does not have any public instance property, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
- If the type corresponding to the type information is
struct
orclass
, the collection contains property information of non-abstract instances inherited from anotherinterface
type.
Type: Collection<InstancePropertyInfo>
prop modifiers
public prop modifiers: Collection<ModifierInfo>
Description: Obtains information about all modifiers of the type corresponding to TypeInfo and returns the corresponding collection.
Note:
- If the type is not modified by any modifiers, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
- By default, the
interface
type has theopen
semantics. Therefore, the returned collection always contains theopen
modifier.- Since the reflection function can only work on types modified by the
public
access control modifier, all access control modifiers are ignored.
Type: Collection<ModifierInfo>
prop name
public prop name: String
Description: Obtains the name of the type corresponding to TypeInfo.
Note:
- The name does not contain any module name prefix or package name prefix.
- The type information of a type alias is the type information of the actual type. Therefore, the function does not return the name of the type alias but the name of the actual type. For example, the name of the type information of the type alias Byte is UInt8 instead of Byte.
Type: String
prop qualifiedName
public prop qualifiedName: String
Description: Obtains the qualified name of the type corresponding to TypeInfo.
Note:
- The qualified name contains the module name prefix and package name prefix.
- In particular, the qualified names of Cangjie built-in data types and all types under the
core
package of thestd
module contain no module name prefix or package name prefix.- All types defined in the context of the default module name and package name have no module name prefix, but have a package name prefix
default
, for example,default.MyType
.
Type: String
prop staticFunctions
public prop staticFunctions: Collection<StaticFunctionInfo>
Description: Obtains information about all public static member functions of the type corresponding to TypeInfo and returns the corresponding collection.
Note:
- If the type corresponding to TypeInfo does not have any public static member function, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
- If the type corresponding to the type information is
struct
,class
, orinterface
, the collection contains information about non-abstract static member functions inherited from anotherinterface
type.
Type: Collection<StaticFunctionInfo>
prop staticProperties
public prop staticProperties: Collection<StaticPropertyInfo>
Description: Obtains information about all public static member properties of the type corresponding to TypeInfo and returns the corresponding collection.
Note:
- If the type corresponding to TypeInfo does not have any public static member property, an empty collection is returned.
- The collection does not guarantee a constant traversal sequence.
- If the type corresponding to the type information is
struct
,class
, orinterface
, the collection contains information about non-abstract static member properties inherited from anotherinterface
type.
Type: Collection<StaticPropertyInfo>
prop superInterfaces
public prop superInterfaces: Collection<InterfaceTypeInfo>
Description: Obtains information about all interface
types that are directly implemented by the type corresponding to TypeInfo and returns the corresponding collection.
Note:
Type: Collection<InterfaceTypeInfo>
static func get(String)
public static func get(qualifiedName: String): TypeInfo
Description: Obtains TypeInfo of the type corresponding to the qualified name of a given type.
Note:
- The type information of a generic type that is not instantiated cannot be obtained.
- Currently, the qualified name
qualifiedName
of a type does not support qualified names ofNothing
, function, tuple, andenum
types, as well asstruct
type with generics.
Parameters:
- qualifiedName: String: qualified name of the type
Returns:
- TypeInfo: type information of the type corresponding to the qualified name
qualifiedName
of the type
Throws:
- InfoNotFoundException: If the type information of the type that matches the qualified name
qualifiedName
of the given type cannot be obtained, this exception is thrown.
static func of(Any)
public static func of(a: Any): TypeInfo
Description: Obtains the type information corresponding to the runtime type of a given instance of any type.
A runtime type is a type determined through dynamic binding when a program is running. A runtime type is bound to an instance object. In scenarios such as inheritance, the runtime type may be inconsistent with the static type.
Note:
Currently, instance
a
does not support instances whose runtime type is function, tuple,enum
, orstruct
with generics.
Parameters:
- a: Any: instance
Returns:
- TypeInfo: type information corresponding to the runtime type of instance
a
Throws:
- InfoNotFoundException: If the type information corresponding to the runtime type of instance
a
cannot be obtained, this exception is thrown.
static func of(Object)
public static func of(a: Object): ClassTypeInfo
Description: Obtains the class
type information corresponding to the runtime type of a given instance of class
type.
Parameters:
- a: Object: instance of
class
type
Returns:
- ClassTypeInfo:
class
type information corresponding to the runtime type of instancea
ofclass
type
Throws:
- InfoNotFoundException: If the
class
type information corresponding to the runtime type of instancea
cannot be obtained, this exception is thrown.
static func of<T>()
public static func of<T>(): TypeInfo
Description: Obtains type information corresponding to a given type.
Notes:
Returns:
- TypeInfo: type information corresponding to the
T
type
Throws:
- InfoNotFoundException: If the type information corresponding to the T type cannot be obtained, this exception is thrown.
func findAnnotation<T>() where T <: Annotation
public func findAnnotation<T>(): Option<T> where T <: Annotation
Description: Attempts to obtain the annotation that is applied to the types corresponding to TypeInfo and has a given qualified name.
Returns:
- Option<T>: If a match is found, the annotation is returned. Otherwise,
None
is returned.
func getInstanceFunction(String, Array<TypeInfo>)
public func getInstanceFunction(name: String, parameterTypes: Array<TypeInfo>): InstanceFunctionInfo
Description: Attempts to obtain information about a matched instance function in a type based on a given function name and a type information list corresponding to the formal parameter type list of the function.
Parameters:
- name: String: function name
- parameterTypes: Array<TypeInfo>: type information list corresponding to the formal parameter type list of the function
Returns:
- InstanceFunctionInfo: If a match is found, information about the instance function is returned.
Throws:
- InfoNotFoundException: If no matched public instance function is found, this exception is thrown.
func getInstanceProperty(String)
public func getInstanceProperty(name: String): InstancePropertyInfo
Description: Attempts to obtain information about the instance property that matches a given property name in the type.
Parameters:
- name: String: property name
Returns:
- InstancePropertyInfo: If a match is found, information about the instance property is returned.
Throws:
- InfoNotFoundException: If no matched public instance property is found, this exception is thrown.
func getStaticFunction(String, Array<TypeInfo>)
public func getStaticFunction(name: String, parameterTypes: Array<TypeInfo>): StaticFunctionInfo
Description: Attempts to obtain information about a matched static member function in the type based on a given function name and a type information list corresponding to the formal parameter type list of the function.
Parameters:
- name: String: function name
- parameterTypes: Array<TypeInfo>: type information list corresponding to the formal parameter type list of the function
Returns:
- StaticFunctionInfo: If a match is found, information about the static member function is returned.
Throws:
- InfoNotFoundException: If no matched public static member function is found, this exception is thrown.
func getStaticProperty(String)
public func getStaticProperty(name: String): StaticPropertyInfo
Description: Attempts to obtain information about the static member property that matches a given property name in the type.
Parameters:
- name: String: property name
Returns:
- StaticPropertyInfo: If a match is found, information about the static member property is returned.
Throws:
- InfoNotFoundException: If no matched public static member property is found, this exception is thrown.
func hashCode()
public func hashCode(): Int64
Description: Obtains the hash value of the type information.
Note:
The internal implementation is the hash value of the qualified name string of the type information.
Returns:
- Int64: hash value of the type information
func isSubtypeOf(TypeInfo)
public func isSubtypeOf(supertype: TypeInfo): Bool
Description: Checks whether the type of the current TypeInfo instance is a subtype of the type represented by the TypeInfo instance specified in the parameter.
Note:
Currently, none of
struct
types can obtain theinterface
type implemented by them. Therefore,false
is always returned when determining whether astruct
is a subtype of aninterface
.
Parameters:
- supertype: TypeInfo: type information of the target type
Returns:
- Bool: If the type corresponding to TypeInfo is a subtype of the type corresponding to
supertype
,true
is returned. Otherwise,false
is returned.
func toString()
public func toString(): String
Description: Obtains the type information in string format.
Note:
The internal implementation is the qualified name string of the type information.
Returns:
- String: type information in string format
operator func !=(TypeInfo)
public operator func !=(that: TypeInfo): Bool
Description: Checks whether the type information is not equal to given type information.
Parameters:
- that: TypeInfo: other type information that is compared for equality
Returns:
- Bool: If the qualified name of the type information is not equal to
that
,true
is returned. Otherwise,false
is returned.
operator func ==(TypeInfo)
public operator func ==(that: TypeInfo): Bool
Description: Checks whether the type information is equal to given type information.
Parameters:
- that: TypeInfo: other type information that is compared for equality
Returns:
- Bool: If the qualified name of the type information is equal to
that
,true
is returned. Otherwise,false
is returned.