Classes

class ClassTypeInfo

public class ClassTypeInfo <: TypeInfo

Description: Describes type information of the class type.

Parent types:

prop constructors

public prop constructors: Collection<ConstructorInfo>

Description: Obtains information about all public constructors in the class type 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>

Examples:

package test

import std.reflect.*

public class Rectangular {
    public var myName = ""
    public init() {}
    public init(name: String) {
        myName = name
    }
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")
    // Obtain constructors.
    for (i in ty.constructors) {
        println(i)
    }
    return
}

Results:

init()
init(String)

prop instanceVariables

public prop instanceVariables: Collection<InstanceVariableInfo>

Description: Obtains information about all public instance variables in the class type 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>

Examples:

package test

import std.reflect.*

public class Rectangular {
    public var length = 4
    public var width = 5
    public var myName = ""
    public init() {}
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")
    // Obtain instance variables.
    for (i in ty.instanceVariables) {
        println(i)
    }
    return
}

Results:

length: Int64
width: Int64
myName: String

prop sealedSubclasses

public prop sealedSubclasses: Collection<ClassTypeInfo>

Description: Obtains 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 the sealed semantics, an empty collection is returned.
  • If the class type has the sealed semantics, the obtained collection cannot be an empty collection because the class type is a subclass of itself.

Type: Collection<ClassTypeInfo>

prop staticVariables

public prop staticVariables: Collection<StaticVariableInfo>

Description: Obtains information about all public static variables in the class type corresponding to ClassTypeInfo and returns the corresponding collection.

NOTE

  • If the class type does not have any public static variable, an empty collection is returned.
  • The collection does not guarantee a constant traversal sequence.
  • The collection does not contain any inherited public static 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 the object class does not have a direct parent class.

Type: Option<ClassTypeInfo>

func construct(Array<Any>)

public func construct(args: Array<Any>): Any

Description: Searches the class type corresponding to ClassTypeInfo for a matched constructor based on an argument list, calls the constructor, passes the argument list, and returns the call result.

Parameters:

Returns:

  • Any: instance of the class type

Throws:

Examples:

package test

import std.reflect.*

public class Rectangular {
    public var length = 4
    public var width = 5
    public var myName = ""
    public init() {}
    public init(name: String) {
        myName = name
    }
    public init(name: String, length: Int64, width: Int64) {
        myName = name
        this.length = length
        this.width = width
    }
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")

    // Construct instances with different input parameters.
    ty.construct()
    ty.construct("Small rectangular")
    ty.construct("Big rectangular", 1, 1)
    return
}

func getConstructor(Array<TypeInfo>)

public func getConstructor(parameterTypes: Array<TypeInfo>): ConstructorInfo

Description: Attempts to obtain information about the public constructor that matches a given parameter type information list from the class type corresponding to ClassTypeInfo.

Parameters:

  • parameterTypes: Array<TypeInfo>: parameter type information list

Returns:

  • ConstructorInfo: If a match is found, information about the public constructor is returned.

Throws:

Examples:

package test

import std.reflect.*

public class Rectangular {
    public var length = 4
    public var width = 5
    public var myName = ""
    public init() {}
    public init(name: String) {
        myName = name
    }
    public init(name: String, length: Int64, width: Int64) {
        myName = name
        this.length = length
        this.width = width
    }
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")

    // Obtain information about a specified constructor.
    let ci01 = ty.getConstructor(StructTypeInfo.get("String"))
    println(ci01)

    // Obtain information about a specified constructor.
    let ci02 = ty.getConstructor(StructTypeInfo.get("String"), PrimitiveTypeInfo.get("Int64"), PrimitiveTypeInfo.get("Int64"))
    println(ci02)
    return
}

Results:

init(String)
init(String, Int64, Int64)

func getInstanceVariable(String)

public func getInstanceVariable(name: String): InstanceVariableInfo

Description: Attempts to obtain information about a matched instance variable in the class type corresponding to ClassTypeInfo based on a given variable name.

Parameters:

Returns:

Throws:

Examples:

package test

import std.reflect.*

public class Rectangular {
    public var length = 4
    public var width = 5
    public var myName = ""
    public init() {}
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")

    // Obtain instance variable information.
    let ivi = ty.getInstanceVariable("myName")
    println(ivi)
    return
}

Results:

myName: String

func getStaticVariable(String)

public func getStaticVariable(name: String): StaticVariableInfo

Description: Attempts to obtain information about a matched static variable in the class type corresponding to ClassTypeInfo based on a given variable name.

Parameters:

Returns:

  • StaticVariableInfo: If a match is found, information about the static variable is returned.

Throws:

Examples:

package test

import std.reflect.*

public class Rectangular {
    public static var area: Int64 = 10
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")

    // Obtain the static variable.
    let sv = ty.getStaticVariable("area")
    println(sv)
    return
}

Results:

static area: Int64

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 the open modifier has the open semantics. For example, an abstract class has the open semantics no matter whether it is modified by the open modifier.

Returns:

  • Bool: If the class type corresponding to ClassTypeInfo has the open 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 the sealed semantics, true is returned. Otherwise, false is returned.

static func get(String)

public redef static func get(qualifiedName: String): ClassTypeInfo

Description: Obtains ClassTypeInfo of the type corresponding to a given qualified name.

Parameters:

  • qualifiedName: String: qualified name of a type

Returns:

  • ClassTypeInfo: type information of the type corresponding to qualifiedName

Throws:

Examples:

import std.reflect.*

public class Rectangular {}

main(): Unit {
    let ty = ClassTypeInfo.get("default.Rectangular")
    println(ty)
    return
}

Results:

default.Rectangular

static func of(Any)

public redef static func of(a: Any): ClassTypeInfo

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.

Parameters:

  • a: Any: instance of any type

Returns:

  • ClassTypeInfo: type information corresponding to the runtime type of instance a

Throws:

Examples:

package test

import std.reflect.*

public class Rectangular {}

main(): Unit {
    var r = Rectangular()
    let ty = ClassTypeInfo.of(r)
    println(ty)
    return
}

Results:

test.Rectangular

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 the class type.

Parameters:

  • a: Object: instance of the class type

Returns:

  • ClassTypeInfo: class type information corresponding to the runtime type of instance a of the class type

Throws:

  • InfoNotFoundException: If the class type information corresponding to the runtime type of instance a cannot be obtained, this exception is thrown.

Examples:

package test

import std.reflect.*

public class Rectangular {}

main(): Unit {
    var r = Rectangular()
    let ty = ClassTypeInfo.of(r)
    println(ty)
    return
}

Results:

test.Rectangular

static func of<T>()

public redef static func of<T>(): ClassTypeInfo

Description: Obtains the type information corresponding to a given T type.

Returns:

Throws:

Examples:

import std.reflect.*

public class Rectangular {}

main(): Unit {
    let ty = ClassTypeInfo.of<Rectangular>()
    println(ty)
    return
}

Results:

default.Rectangular

class ConstructorInfo

public class ConstructorInfo <: Equatable<ConstructorInfo> & Hashable & ToString

Description: Describes constructor information.

Parent types:

prop annotations

public prop annotations: Collection<Annotation>

Description: Obtains all annotations applied to the constructor corresponding to ConstructorInfo and returns the corresponding collection.

NOTE

  • If no annotation is applied to the constructor 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: ReadOnlyList<ParameterInfo>

Description: Obtains the parameter type list of the constructor corresponding to ConstructorInfo.

NOTE

The parameter sequence is not guaranteed. You can determine the actual position of a parameter based on the index property of ParameterInfo.

Type: ReadOnlyList<ParameterInfo>

Examples:

package test

import std.reflect.*

public class Rectangular {
    public var length = 4
    public var width = 5
    public var myName = ""
    public init() {}
    public init(name: String) {
        myName = name
    }
    public init(name: String, length: Int64, width: Int64) {
        myName = name
        this.length = length
        this.width = width
    }
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")
    // Obtain constructors.
    for (i in ty.constructors) {
        // Obtain parameters.
        for (j in i.parameters) {
            println("*${i}* has an input parameter of the *${j}* type.")
        }
    }
    return
}

Results:

init(String) has an input parameter of the String type.
init(String, Int64, Int64) has an input parameter of the String type.
init(String, Int64, Int64) has an input parameter of the Int64 type.
init(String, Int64, Int64) has an input parameter of the Int64 type.

func apply(Array<Any>)

public func apply(args: Array<Any>): Any

Description: Calls the constructor corresponding to ConstructorInfo, passes the argument list, and returns the call result.

NOTE

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 a type that is an abstract class, this exception is thrown.
  • IllegalArgumentException: If the number of arguments in the argument list args is not equal to that of parameters in the parameter list of the constructor corresponding to the constructor information, this exception is thrown.
  • IllegalTypeException: If the runtime type of any argument in the argument list args is not a subtype of the declaring type of the corresponding parameter in the constructor corresponding to the constructor information, this exception is thrown.
  • Exception: If an exception is thrown inside the called constructor corresponding to the 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 constructor 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 information about the other constructor.

Parameters:

  • that: ConstructorInfo: information about the other constructor to be compared with

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 information about the other constructor.

Parameters:

  • that: ConstructorInfo: information about the other constructor to be compared with

Returns:

  • Bool: If the constructor information is equal to that, true is returned. Otherwise, false is returned.

class GenericTypeInfo

public class GenericTypeInfo <: TypeInfo & Equatable<GenericTypeInfo>

Description: Describes generic type information.

Parent types:

operator func ==(GenericTypeInfo)

public operator func ==(that: GenericTypeInfo): Bool

Description: Checks whether the generic type information is equal to information about the other generic type.

Parameters:

  • that: GenericTypeInfo: information about the other generic type to be compared with

Returns:

  • Bool: If the generic type 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 types:

prop annotations

public prop annotations: Collection<Annotation>

Description: Obtains all annotations applied to the global function corresponding to GlobalFunctionInfo and returns the corresponding collection.

NOTE

  • If no annotation is applied to the global function corresponding to the global function information, an empty collection is returned.
  • The collection does not guarantee a constant traversal sequence.

Type: Collection<Annotation>

prop genericParams

public prop genericParams: Collection<GenericTypeInfo>

Description: Obtains the generic parameter information list of the instance function corresponding to GlobalFunctionInfo.

Type: Collection<GenericTypeInfo>

Throws:

prop name

public prop name: String

Description: Obtains the name of the global function corresponding to GlobalFunctionInfo.

NOTE

All global functions that are overloaded have the same name.

Type: String

prop parameters

public prop parameters: ReadOnlyList<ParameterInfo>

Description: Obtains the parameter information list of the global function corresponding to GlobalFunctionInfo.

NOTE

The parameter sequence is not guaranteed. You can determine the actual position of a parameter based on the index property of ParameterInfo.

Type: ReadOnlyList<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 argument list, and returns the call result.

NOTE

The argument types in args must exactly match the input parameter types of the function. Otherwise, the parameter check fails.

Parameters:

Returns:

  • Any: call result of the global function

Throws:

  • InvocationTargetException: If a function with generic parameters calls the method, this exception is thrown.
  • IllegalArgumentException: If the number of arguments in the argument list args is not equal to that of parameters in the parameter list of the global function corresponding to the global function information GlobalFunctionInfo, this exception is thrown.
  • IllegalTypeException: If the runtime type of any argument in the argument list args is not a subtype of the declaring type of the corresponding parameter in the global function corresponding to the global function information, this exception is thrown.
  • Exception: If an exception is thrown inside the called global function corresponding to the global function information, the exception is encapsulated as Exception and thrown.

func apply(Array<TypeInfo>, Array<Any>)

public func apply(genericTypeArgs: Array<TypeInfo>, args: Array<Any>): Any

Description: Calls the global generic function corresponding to GlobalFunctionInfo, passes the generic parameter type list and argument list, and returns the call result.

NOTE

The argument types in args must exactly match the input parameter types of the function. Otherwise, the parameter check fails.

Parameters:

Returns:

  • Any: call result of the global function

Throws:

  • InvocationTargetException: If a non-generic function calls the method, this exception is thrown.
  • IllegalArgumentException: If the number of arguments in the argument list args is not equal to that of parameters in the parameter list of the global function corresponding to the global function information GlobalFunctionInfo, this exception is thrown.
  • IllegalArgumentException: If the number of parameters in the generic parameter list genericTypeArgs of the function is not equal to that of parameters in the generic parameter list genericParams of the global function corresponding to the global function information, this exception is thrown.
  • IllegalTypeException: If the runtime type of any argument in the argument list args is not a subtype of the declaring type of the corresponding parameter in the global function corresponding to the global function information, this exception is thrown.
  • IllegalTypeException: If the passed parameter list args and generic parameter type list genericTypeArgs do not meet the type constraints for the parameters of the global function corresponding to the global function information, this exception is thrown.
  • Exception: If an exception is thrown inside the called global function corresponding to the global 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 global function corresponding to GlobalFunctionInfo 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 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 information about the other global function.

Parameters:

  • that: GlobalFunctionInfo: information about the other global function to be compared with

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 information about the other global function.

Parameters:

  • that: GlobalFunctionInfo: information about the other global function to be compared with

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

prop annotations

public prop annotations: Collection<Annotation>

Description: Obtains all annotations applied to the global variable corresponding to GlobalVariableInfo and returns the corresponding collection.

NOTE

  • If no annotation is applied to the global variable corresponding to the global variable information, an empty collection is returned.
  • The collection does not guarantee a constant traversal sequence.

Type: Collection<Annotation>

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 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 global variable corresponding to GlobalVariableInfo 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 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 variable corresponding to GlobalVariableInfo can be modified.

NOTE

  • If a global variable has the var modifier, it can be modified.
  • If a global variable has the let modifier, it cannot be modified.
  • Any global variable of the struct type 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 information about the other global variable.

Parameters:

  • that: GlobalVariableInfo: information about the other global variable to be compared with

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 information about the other global variable.

Parameters:

  • that: GlobalVariableInfo: information about the other global variable to be compared with

Returns:

  • Bool: If the global variable information is not equal to that, true is returned. Otherwise, false is returned.

class InstanceFunctionInfo

public class InstanceFunctionInfo <: Equatable<InstanceFunctionInfo> & Hashable & ToString

Description: Describes instance function information.

Parent types:

prop annotations

public prop annotations: Collection<Annotation>

Description: Obtains all annotations applied to the instance function corresponding to InstanceFunctionInfo and returns the corresponding collection.

NOTE

  • If no annotation is applied to the instance function corresponding to the instance function information, an empty collection is returned.
  • The collection does not guarantee a constant traversal sequence.

Type: Collection<Annotation>

prop genericParams

public prop genericParams: Collection<GenericTypeInfo>

Description: Obtains the generic parameter information list of the instance function corresponding to InstanceFunctionInfo.

Type: Collection<GenericTypeInfo>

Throws:

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 the instance function has no modifier, 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 are overloaded 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: ReadOnlyList<ParameterInfo>

Description: Obtains the parameter information list of the instance function corresponding to InstanceFunctionInfo.

NOTE

The parameter sequence is not guaranteed. You can determine the actual position of a parameter based on the index property of ParameterInfo.

Type: ReadOnlyList<ParameterInfo>

prop returnType

public prop returnType: TypeInfo

Description: Obtains the return 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 argument list, and returns the call result.

NOTE

The argument types in args must exactly match the input parameter types of the function.

Parameters:

  • instance: Any: instance
  • args: Array<Any>: argument list

Returns:

  • Any: call result of the instance function

Throws:

  • InvocationTargetException: If a function with generic parameters calls the method, this exception is thrown.
  • InvocationTargetException: If the instance function corresponding to the instance function information is abstract, or the corresponding function implementation does not exist, this exception is thrown.
  • IllegalArgumentException: If the number of arguments in the argument list args is not equal to that of parameters in the parameter list of the instance function corresponding to the instance function information, this exception is thrown.
  • IllegalTypeException: If the runtime type of instance is different from the type of the instance function corresponding to the instance function information, this exception is thrown.
  • IllegalTypeException: If the runtime type of any argument in the argument list args is not a subtype of the declaring type of the corresponding parameter in the instance function corresponding to the instance function information, this exception is thrown.
  • Exception: If an exception is thrown inside the called instance function corresponding to the instance function information, the exception is encapsulated as Exception and thrown.

func apply(Any, Array<TypeInfo>, Array<Any>)

public func apply(instance: Any, genericTypeArgs: Array<TypeInfo>, args: Array<Any>): Any

Description: Calls the generic instance function corresponding to InstanceFunctionInfo, specifies an instance, passes the type list and parameter list of generic parameters, and returns the call result.

NOTE

The parameter types in args must exactly match the input parameter types of the function.

Parameters:

  • instance: Any: instance
  • genericTypeArgs: Array<TypeInfo>: generic parameter type information list
  • args: Array<Any>: generic parameter list

Returns:

  • Any: call result of the generic instance function

Throws:

  • InvocationTargetException: If the instance function corresponding to the function information is abstract or does not have a function body, this exception is thrown.
  • InvacationTargetException: If a non-generic function calls the method, this exception is thrown.
  • IllegalTypeException: If the runtime type of instance is different from the type of the instance function corresponding to the instance function information, this exception is thrown.
  • IllegalArgumentException: If the number of arguments in the generic parameter list args is not equal to that of parameters in the parameter list of the instance function corresponding to the instance function information, this exception is thrown.
  • IllegalArgumentException: If the number of parameters in the generic parameter type information list genericTypeArgs of the function is not equal to that of parameters in the generic parameter type information list genericParams of the instance function corresponding to the instance function information, this exception is thrown.
  • IllegalTypeException: If the runtime type of any parameter in the generic parameter list args is not a subtype of the declaring type of the corresponding parameter in the instance function corresponding to the instance function information, this exception is thrown.
  • IllegalTypeException: If the passed generic parameter list args and generic parameter type information list genericTypeArgs do not meet the type constraints for the parameters of the instance function corresponding to the instance function information, this exception is thrown.
  • Exception: If an exception is thrown inside the called instance function corresponding to the instance function information, the exception is encapsulated as Exception and thrown.

Examples:

import std.reflect.*

public class Rectangular {
    public var length = 4
    public var width = 5
    public func area(): Int64 {
        return length * width
    }
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("default.Rectangular")
    // Obtain InstanceFunctionInfo.
    var gif = ty.getInstanceFunction("area")

    // Call the reflection function.
    var r = Rectangular()
    var result = gif.apply(r) as Int64
    println(result)
    return
}

Results:

Some(20)

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 function 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, all instance functions in the interface type have the open 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 information about the other instance function.

Parameters:

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 information about the other instance function.

Parameters:

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

prop annotations

public prop annotations: Collection<Annotation>

Description: Obtains all annotations applied to the instance property corresponding to InstancePropertyInfo and returns the corresponding collection.

NOTE

  • If no annotation is applied to the instance property 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 has no modifier, 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 property 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 given instance.

NOTE

Currently, any instance of the struct type is not supported.

Parameters:

  • instance: Any: instance

Returns:

  • Any: value of the instance property in instance

Throws:

  • IllegalTypeException: If the runtime type of instance is not strictly the same as the type of the instance property corresponding to the instance property information, this exception is thrown.

Examples:

import std.reflect.*

public class Rectangular {
    public var length = 4
    public prop width: Int64 {
        get() {
            5
        }
    }
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("default.Rectangular")
    // Obtain InstancePropertyInfo.
    var gip = ty.getInstanceProperty("width")

    // Obtain the instance value.
    var r = Rectangular()
    var result = gip.getValue(r) as Int64
    println(result)
    return
}

Results:

Some(5)

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 isAbstract()

public func isAbstract(): Bool

Description: Checks whether the instance property corresponding to InstancePropertyInfo is abstract.

Returns:

  • Bool: If the instance property corresponding to InstancePropertyInfo is abstract, true is returned. Otherwise, false is returned.

func isOpen()

public func isOpen(): Bool

Description: Checks whether the instance property corresponding to InstancePropertyInfo has the open semantics.

Returns:

  • Bool: If the instance property corresponding to InstancePropertyInfo has the open semantics, true is returned. Otherwise, false is returned.

func isMutable()

public func isMutable(): Bool

Description: Checks whether the instance property corresponding to InstancePropertyInfo can be modified.

NOTE

  • If an instance property has the mut modifier, it can be modified. Otherwise, it cannot be modified.
  • Any instance property in any instance of the struct type cannot be modified.
  • Any instance property of the struct type cannot be modified.

Returns:

  • Bool: If the instance property 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 given instance.

NOTE

Currently, any instance of the struct type is not supported.

Parameters:

  • instance: Any: instance
  • newValue: Any: new value

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 the same as 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 information about the other instance property.

Parameters:

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 information about the other instance property.

Parameters:

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

prop annotations

public prop annotations: Collection<Annotation>

Description: Obtains all annotations applied to the instance variable corresponding to InstanceVariableInfo and returns the corresponding collection.

NOTE

  • If no annotation is applied to the instance variable 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 the instance variable has no modifier, 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 variable 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, any instance of the struct type is not supported.
  • 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 the same as the type of the instance variable corresponding to the instance variable information, this exception is thrown.

Examples:

import std.reflect.*

public class Rectangular {
    public var length = 4
    public var width = 5
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("default.Rectangular")
    // Obtain InstanceVariableInfo.
    var gip = ty.getInstanceVariable("width")
    // Obtain the instance value.
    var r = Rectangular()
    let v = gip.getValue(r) as Int64
    println(v)
    return
}

Results:

Some(5)

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 variable corresponding to InstanceVariableInfo can be modified.

NOTE

  • If an instance variable has the var modifier, it can be modified.
  • If an instance variable has the let modifier, it cannot be modified.
  • Any instance variable in any instance of the struct type cannot be modified.
  • Any instance variable of the struct type cannot be modified.

Returns:

  • Bool: If the instance variable 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, any instance of the struct type is not supported.

Parameters:

  • instance: Any: instance
  • newValue: Any: new value

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 the same as 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 variable 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 information about the other instance variable.

Parameters:

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 information about the other instance variable.

Parameters:

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: Describes type information of the interface type.

Parent types:

prop sealedSubtypes

public prop sealedSubtypes: Collection<TypeInfo>

Description: Obtains 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 the sealed semantics, an empty collection is returned.
  • If the interface type has the sealed semantics, the obtained collection cannot be an empty collection because the interface type is a subtype of itself.

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 the sealed semantics, true is returned. Otherwise, false is returned.

static func get(String)

public redef static func get(qualifiedName: String): InterfaceTypeInfo

Description: Obtains InterfaceTypeInfo of the type corresponding to qualifiedName.

Parameters:

  • qualifiedName: String: qualified name of a type

Returns:

  • InterfaceTypeInfo: type information of the Interface type corresponding to qualifiedName

Throws:

Examples:

import std.reflect.*

public interface Rectangular {}

main(): Unit {
    let ty = InterfaceTypeInfo.get("default.Rectangular")
    println(ty)
    return
}

Results:

default.Rectangular

static func of(Any)

public redef static func of(a: Any): InterfaceTypeInfo

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.

Parameters:

  • a: Any: instance of any type

Returns:

  • InterfaceTypeInfo: type information corresponding to the runtime type of instance a

Throws:

static func of<T>()

public redef static func of<T>(): InterfaceTypeInfo

Description: Obtains the type information corresponding to a given T type.

Returns:

Throws:

class PackageInfo

public class PackageInfo <: Equatable<PackageInfo> & Hashable & ToString

Description: Describes package information.

Parent types:

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 is d.

Type: String

prop parentPackage

public prop parentPackage: PackageInfo

Description: Obtains the package information of the parent package corresponding to PackageInfo.

Type: PackageInfo

Throws:

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 name a/b.c.d is in package c within package b under module a.

Type: String

prop rootPackage

public prop rootPackage: PackageInfo

Description: Obtains PackageInfo of the root package corresponding to PackageInfo.

NOTE

If the package is a root package, the rootPackage property returns the package itself. For example, if the qualified name of the package is a.b.c, rootPackage returns a; if the qualified name of the package is a, rootPackage returns a.

Type: PackageInfo

Throws:

prop subPackages

public prop subPackages: Collection<PackageInfo>

Description: Obtains the collection of PackageInfo of all subpackages corresponding to PackageInfo.

NOTE

  • This property returns only the subpackages that have been loaded.
  • The return result sequence is not guaranteed.

Type: Collection<PackageInfo>

prop typeInfos

public prop typeInfos: Collection<TypeInfo>

Description: Obtains 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 any type 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>

prop version

public prop version: String

Description: Obtains the version number of the package corresponding to PackageInfo.

NOTE

Currently, there is no version information in the dynamic library. Therefore, the obtained version number is always an empty string.

Type: String

static func get(String)

public static func get(qualifiedName: String): PackageInfo

Description: Obtains PackageInfo corresponding to qualifiedName.

Parameters:

  • qualifiedName: String: qualified name of a type

Returns:

  • PackageInfo: package information corresponding to qualifiedName of the type

Throws:

  • InfoNotFoundException: If the type information corresponding to qualifiedName of the type cannot be obtained, this exception is thrown.

static func load(String)

public static func load(path: String): PackageInfo

Description: Dynamically loads a Cangjie dynamic library module in a specified path and obtains information about the module at runtime.

NOTE

  • To improve compatibility, the shared library file name in path does not contain an extension (such as .so and .dll).
  • If a package has been imported in static loading mode (for example, import), an exception is thrown when the package is dynamically loaded.

Parameters:

  • path: String: absolute or relative path of the shared library file

Returns:

  • PackageInfo: specified package information of the Cangjie dynamic library

Throws:

  • ReflectException: If the shared library fails to be loaded, this exception is thrown.
  • ReflectException: If a shared library with the same package name or file name is loaded repeatedly, this exception is thrown.
  • ReflectException: If the dynamic library contains multiple packages, this exception is thrown.
  • IllegalArgumentException: If the path is invalid, this exception is thrown.

func getFunction(String, Array<TypeInfo>)

public func getFunction(name: String, parameterTypes: Array<TypeInfo>): GlobalFunctionInfo

Description: Attempts to obtain information about a matched public global function in the package corresponding to PackageInfo based on a given function name and parameter type information list.

Parameters:

  • name: String: global function name
  • parameterTypes: Array<TypeInfo>: parameter type information list

Returns:

  • GlobalFunctionInfo: If a match is found, information about the globally defined public function is returned.

Throws:

  • InfoNotFoundException: If no matched globally defined public function is found, this exception is thrown.

func getFunctions(String)

public func getFunctions(name: String): Array<GlobalFunctionInfo>

Description: Attempts to obtain information about all public global functions with a given function name from the package corresponding to PackageInfo.

Parameters:

  • name: String: global function name

Returns:

func getSubPackage(String)

public func getSubPackage(qualifiedName: String): PackageInfo

Description: Attempts to obtain information about the subpackage with the qualified name qualifiedName and corresponding to PackageInfo.

Parameters:

  • qualifiedName: String: qualified name of a subpackage

Returns:

Throws:

func getTypeInfo(String)

public func getTypeInfo(qualifiedTypeName: String): TypeInfo

Description: Attempts to obtain type information of the globally defined public type with a given type name from the package corresponding to PackageInfo.

Parameters:

  • qualifiedTypeName: String: qualified name of a type

Returns:

  • TypeInfo: If a match is found, the type information of the globally defined public type is returned.

Throws:

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

Returns:

  • GlobalVariableInfo: If a match is found, information about the globally defined public variable is returned.

Throws:

  • InfoNotFoundException: If no matched globally defined public 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 to obtain the qualified name string in 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 information about the other package.

NOTE

The internal implementation is to compare whether the qualified name in the package information is equal to that in the information about the other package.

Parameters:

  • that: PackageInfo: information about the other package to be compared with

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 information about the other package.

NOTE

The internal implementation is to compare whether the qualified name in the package information is equal to that in the information about the other package.

Parameters:

  • that: PackageInfo: information about the other package to be compared with

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 function parameter information.

Parent types:

prop annotations

public prop annotations: Collection<Annotation>

Description: Obtains all annotations applied to the function parameter corresponding to ParameterInfo and returns the corresponding collection.

NOTE

  • If no annotation is applied to the function parameter corresponding to the function 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 parameter corresponding to ParameterInfo in the function.

NOTE

The value of index starts from 0.

Type: Int64

prop name

public prop name: String

Description: Obtains the name of the parameter corresponding to ParameterInfo.

Type: String

prop typeInfo

public prop typeInfo: TypeInfo

Description: Obtains the declaring type information of the function parameter 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 function parameter 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 function parameter information.

Returns:

  • Int64: hash value of the function parameter information

func toString()

public func toString(): String

Description: Obtains the function parameter information in string format.

Returns:

  • String: function parameter information in string format

operator func !=(ParameterInfo)

public operator func !=(that: ParameterInfo): Bool

Description: Checks whether the function parameter information is not equal to information about the other function parameter.

Parameters:

  • that: ParameterInfo: information about the other function parameter to be compared with

Returns:

  • Bool: If the function parameter information 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 function parameter information is equal to information about the other function parameter.

Parameters:

  • that: ParameterInfo: information about the other function parameter to be compared with

Returns:

  • Bool: If the function parameter information 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, and UIntNative), and floating-point (Float16, Float32, and Float64) types.

NOTE

Currently, the Nothing primitive data type is not supported.

Parent types:

static func get(String)

public redef static func get(qualifiedName: String): PrimitiveTypeInfo

Description: Obtains PrimitiveTypeInfo of the type corresponding to a given qualified name.

Parameters:

  • qualifiedName: String: qualified name of a type

Returns:

Throws:

Examples:

import std.reflect.*

main(): Unit {
    var pti = PrimitiveTypeInfo.get("Int64")
    println(pti)
    return
}

Results:

Int64

static func of(Any)

public redef static func of(a: Any): PrimitiveTypeInfo

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.

Parameters:

  • a: Any: instance of any type

Returns:

  • PrimitiveTypeInfo: type information corresponding to the runtime type of instance a

Throws:

Examples:

import std.reflect.*

main(): Unit {
    var a = 10
    var pti = PrimitiveTypeInfo.of(a)
    println(pti)
    return
}

Results:

Int64

static func of<T>()

public redef static func of<T>(): PrimitiveTypeInfo

Description: Obtains the type information corresponding to a given T type.

Returns:

Throws:

Examples:

import std.reflect.*

main(): Unit {
    var pti = PrimitiveTypeInfo.of<Int64>()
    println(pti)
    return
}

Results:

Int64

class StaticFunctionInfo

public class StaticFunctionInfo <: Equatable<StaticFunctionInfo> & Hashable & ToString

Description: Describes static function information.

Parent types:

prop annotations

public prop annotations: Collection<Annotation>

Description: Obtains all annotations applied to the static function corresponding to StaticFunctionInfo and returns the corresponding collection.

NOTE

  • If no annotation is applied to the static function corresponding to StaticFunctionInfo, an empty collection is returned.
  • The collection does not guarantee a constant traversal sequence.

Type: Collection<Annotation>

prop genericParams

public prop genericParams: Collection<GenericTypeInfo>

Description: Obtains the generic parameter information list of the instance function corresponding to StaticFunctionInfo.

Type: Collection<GenericTypeInfo>

Throws:

prop modifiers

public prop modifiers: Collection<ModifierInfo>

Description: Obtains information about all modifiers of the static function corresponding to StaticFunctionInfo and returns the corresponding collection.

NOTE

  • If the static function has no modifier, 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 function corresponding to StaticFunctionInfo.

NOTE

All static functions that are overloaded have the same name.

Type: String

prop parameters

public prop parameters: ReadOnlyList<ParameterInfo>

Description: Obtains the parameter information list of the static function corresponding to StaticFunctionInfo.

NOTE

The parameter sequence is not guaranteed. You can determine the actual position of a parameter based on the index property of ParameterInfo.

Type: ReadOnlyList<ParameterInfo>

prop returnType

public prop returnType: TypeInfo

Description: Obtains the return type information of the static function corresponding to StaticFunctionInfo.

Type: TypeInfo

func apply(TypeInfo, Array<Any>)

public func apply(thisType: TypeInfo, args: Array<Any>): Any

Description: Calls the static function corresponding to StaticFunctionInfo, passes the type information and argument list for the method, and returns the call result.

NOTE

The argument types in args must exactly match the input parameter types of the function. Otherwise, the parameter check fails.

Parameters:

  • thisType: TypeInfo: class to which the method belongs
  • args: Array<Any>: argument list

Returns:

  • Any: call result of the static function

Throws:

  • InvocationTargetException: If the static function corresponding to the function information has generic parameters, this exception is thrown.
  • InfoNotFoundException: If the function body of the static function corresponding to the function information is not implemented, this exception is thrown.
  • IllegalArgumentException: If the number of arguments in the argument list args is not equal to that of parameters in the parameter list of the static function corresponding to the static function information, this exception is thrown.
  • IllegalArgumentException: If thisType is inconsistent with the function signature of the static function, this exception is thrown.
  • IllegalTypeException: If the runtime type of any argument in the argument list args is not a subtype of the declaring type of the corresponding parameter in the static function corresponding to the static function information, this exception is thrown.
  • Exception: If an exception is thrown inside the called static function corresponding to the static function information, the exception is encapsulated as Exception and thrown.

Examples:

package test

import std.reflect.*

public class Rectangular {
    public static func myName(): String { "my name is Rectangular" }
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")

    // Obtain the static function.
    let sf = ty.getStaticFunction("myName")
    
    let result = sf.apply(ty) as String
    println(result)
    return
}

Results:

Some(my name is Rectangular)

func apply(TypeInfo, Array<TypeInfo>, Array<Any>)

public func apply(thisType: TypeInfo, genericTypeArgs: Array<TypeInfo>, args: Array<Any>): Any

Description: Calls the static function corresponding to StaticFunctionInfo, passes the type information and argument list for the method, and returns the call result.

NOTE

The argument types in args must exactly match the input parameter types of the function. Otherwise, the parameter check fails.

Parameters:

  • thisType: TypeInfo: class to which the method belongs
  • genericTypeArgs: Array<TypeInfo>: generic parameter type list
  • args: Array<Any>: argument list

Returns:

  • Any: call result of the static function

Throws:

  • InvocationTargetException: If the static function corresponding to the function information is a non-generic function, this exception is thrown.
  • InfoNotFoundException: If the function body of the static function corresponding to the function information is not implemented, this exception is thrown.
  • IllegalArgumentException: If the number of arguments in the argument list args is not equal to that of parameters in the parameter list of the static function corresponding to the static function information, this exception is thrown.
  • IllegalArgumentException: If the number of generic parameters in the argument list args is not equal to that of generic parameters corresponding to the static function information, this exception is thrown.
  • IllegalArgumentException: If thisType is inconsistent with the function signature of the static function, this exception is thrown.
  • IllegalTypeException: If the runtime type of any argument in the argument list args is not a subtype of the declaring type of the corresponding parameter in the static function corresponding to the static function information, this exception is thrown.
  • IllegalTypeException: If the passed parameter list args and generic parameter type list genericTypeArgs do not meet the type constraints for the parameters of the static function corresponding to the static function information, this exception is thrown.
  • Exception: If an exception is thrown inside the called static function corresponding to the static 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 function 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 function information.

Returns:

  • Int64: hash value of the static function information

func toString()

public func toString(): String

Description: Obtains the static function information in string format.

Returns:

  • String: static function information in string format

operator func !=(StaticFunctionInfo)

public operator func !=(that: StaticFunctionInfo): Bool

Description: Checks whether the static function information is not equal to information about the other static function.

Parameters:

  • that: StaticFunctionInfo: information about the other static function to be compared with

Returns:

  • Bool: If the static 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 function information is equal to information about the other static function.

Parameters:

  • that: StaticFunctionInfo: information about the other static function to be compared with

Returns:

  • Bool: If the static function information is equal to that, true is returned. Otherwise, false is returned.

class StaticPropertyInfo

public class StaticPropertyInfo <: Equatable<StaticPropertyInfo> & Hashable & ToString

Description: Describes static property information.

Parent types:

prop annotations

public prop annotations: Collection<Annotation>

Description: Obtains the collection of all annotations applied to the static property corresponding to StaticPropertyInfo.

NOTE

  • If no annotation is applied to the static property corresponding to the static 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 property corresponding to StaticPropertyInfo and returns the corresponding collection.

NOTE

  • If the static property has no modifier, 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 property corresponding to StaticPropertyInfo.

Type: String

prop typeInfo

public prop typeInfo: TypeInfo

Description: Obtains the declaring type information of the static 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 property 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 property corresponding to StaticPropertyInfo.

NOTE

If the static property lacks a valid implementation, for example, it is an abstract static property in the interface type, UnsupportedException must be thrown. However, this has not been implemented yet due to the lack of support by the backend.

Returns:

  • Any: value of the static property

Examples:

package test

import std.reflect.*

public class Rectangular {
    public static prop sides: Int64 {
        get() { 4 }
    }
    public static prop angles: Int64 {
        get() { 4 }
    }
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")

    // Obtain the static property.
    let sp = ty.getStaticProperty("sides")
    
    let result = sp.getValue() as Int64
    println(result)
    return
}

Results:

Some(4)

func hashCode()

public func hashCode(): Int64

Description: Obtains the hash value of the static property information.

Returns:

  • Int64: hash value of the static property information

func isMutable()

public func isMutable(): Bool

Description: Checks whether the static property corresponding to the static property information can be modified.

Returns:

  • Bool: If the static property corresponding to the static property information can be modified, true is returned. Otherwise, false is returned.

NOTE

  • If a static property has the mut modifier, it can be modified. Otherwise, it cannot be modified.
  • Any static property in any struct type cannot be modified.
  • Any static property of the struct type cannot be modified.

func setValue(Any)

public func setValue(newValue: Any): Unit

Description: Sets the value of the static property corresponding to StaticPropertyInfo.

NOTE

If the static property lacks a valid implementation, for example, it is an abstract static property in the interface type, UnsupportedException must 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 property corresponding to the static 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 property corresponding to the static property information, this exception is thrown.

Examples:

package test

import std.reflect.*

public class Rectangular {
    private static var valueArea = 0
    public static mut prop area: Int64 {
        get() { valueArea }
        set(v) { valueArea = v }
    }
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")

    // Obtain the static property.
    let sp = ty.getStaticProperty("area")
    
    // Set the value of the static property.
    sp.setValue(10)
    let result = sp.getValue() as Int64
    println(result)
    return
}

Results:

Some(10)

func toString()

public func toString(): String

Description: Obtains the static property information in string format.

Returns:

  • String: static property information in string format

operator func !=(StaticPropertyInfo)

public operator func !=(that: StaticPropertyInfo): Bool

Description: Checks whether the static property information is not equal to information about the other static property.

Parameters:

  • that: StaticPropertyInfo: information about the other static property to be compared with

Returns:

  • Bool: If the static 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 property information is equal to information about the other static property.

Parameters:

  • that: StaticPropertyInfo: information about the other static property to be compared with

Returns:

  • Bool: If the static 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 variable information.

Parent types:

prop annotations

public prop annotations: Collection<Annotation>

Description: Obtains all annotations applied to the static variable corresponding to StaticVariableInfo and returns the corresponding collection.

NOTE

  • If no annotation is applied to the static variable 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 variable corresponding to StaticVariableInfo and returns the corresponding collection.

NOTE

  • If the static variable has no modifier, 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 variable corresponding to StaticVariableInfo.

Type: String

prop typeInfo

public prop typeInfo: TypeInfo

Description: Obtains the declaring type information of the static variable 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 variable 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 variable corresponding to StaticVariableInfo.

Returns:

  • Any: value of the static variable

NOTE

  • The return value cannot be of the struct type.

Examples:

package test

import std.reflect.*

public class Rectangular {
    public static var area: Int64 = 10
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")

    // Obtain the static variable.
    let sv = ty.getStaticVariable("area")
    // Obtain the value.
    println(sv.getValue() as Int64)
    return
}

Results:

Some(10)

func hashCode()

public func hashCode(): Int64

Description: Obtains the hash value of the static variable information.

Returns:

  • Int64: hash value of the static variable information

func isMutable()

public func isMutable(): Bool

Description: Checks whether the static variable corresponding to StaticVariableInfo can be modified.

NOTE

  • If a static variable has the var modifier, it can be modified.
  • If a static variable has the let modifier, it cannot be modified.
  • Any static variable in any struct type cannot be modified.
  • Any static variable of the struct type cannot be modified.

Returns:

  • Bool: If the static variable corresponding to the static 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 variable corresponding to StaticVariableInfo.

Parameters:

  • newValue: Any: new value

Throws:

  • IllegalSetException: If the static 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 variable corresponding to the static variable information, this exception is thrown.

Examples:

package test

import std.reflect.*

public class Rectangular {
    public static var area: Int64 = 10
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")

    // Obtain the static variable.
    let sv = ty.getStaticVariable("area")

    // Set the value.
    sv.setValue(20)
    println(sv.getValue() as Int64)
    return
}

Results:

Some(20)

func toString()

public func toString(): String

Description: Obtains the static variable information in string format.

Returns:

  • String: static variable information in string format

operator func !=(StaticVariableInfo)

public operator func !=(that: StaticVariableInfo): Bool

Description: Checks whether the static variable information is not equal to information about the other static variable.

Parameters:

  • that: StaticVariableInfo: information about the other static variable to be compared with

Returns:

  • Bool: If the static 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 variable information is equal to information about the other static variable.

Parameters:

  • that: StaticVariableInfo: information about the other static variable to be compared with

Returns:

  • Bool: If the static variable information is equal to that, true is returned. Otherwise, false is returned.

class StructTypeInfo

public class StructTypeInfo <: TypeInfo

Description: Describes type information of the struct type.

Parent types:

prop constructors

public prop constructors: Collection<ConstructorInfo>

Description: Obtains information about all public constructors in the struct type 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 in the struct type 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 variables in the struct type corresponding to StructTypeInfo and returns the corresponding collection.

NOTE

  • If the struct type does not have any public static 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 the struct type corresponding to StructTypeInfo for a matched constructor based on an argument list, calls the constructor, passes the argument list, and returns the call result.

Parameters:

Returns:

  • Any: instance of the struct type

Throws:

Examples:

import std.reflect.*

public struct Rectangular {
    public var length = 4
    public var width = 5
    public init() {}
    public init(length: Int64, width: Int64) {
        this.length = length
        this.width = width
    }
}

main(): Unit {
    // Obtain StructTypeInfo through the qualified name of the Rectangular type. You can also obtain StructTypeInfo through an instance.
    let ty = StructTypeInfo.get("default.Rectangular")
    // Match a constructor and call it.
    let v = ty.construct(2, 3) as Rectangular
    println(v.getOrThrow().length)
    return
}

Results:

2

func getConstructor(Array<TypeInfo>)

public func getConstructor(parameterTypes: Array<TypeInfo>): ConstructorInfo

Description: Attempts to obtain information about the public constructor that matches a given parameter type information list from the struct type corresponding to StructTypeInfo.

Parameters:

  • parameterTypes: Array<TypeInfo>: parameter type information list

Returns:

  • ConstructorInfo: If a match is found, information about the public constructor is returned.

Throws:

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:

Returns:

Throws:

Examples:

package test

import std.reflect.*

public class Rectangular {
    public var length = 4
    public var width = 5
    public var myName = ""
    public init() {}
}

main(): Unit {
    // Obtain ClassTypeInfo through the qualified name of the Rectangular type. You can also obtain ClassTypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")

    // Obtain structure instance variable information.
    let ivi = ty.getInstanceVariable("myName")
    println(ivi)
    return
}

Results:

myName: String

func getStaticVariable(String)

public func getStaticVariable(name: String): StaticVariableInfo

Description: Attempts to obtain information about a matched static variable in the struct type corresponding to StructTypeInfo based on a given variable name.

Parameters:

Returns:

  • StaticVariableInfo: If a match is found, information about the static variable is returned.

Throws:

Examples:

package test

import std.reflect.*

public struct Rectangular {
    public static var area: Int64 = 10
}

main(): Unit {
    // Obtain StructTypeInfo through the qualified name of the Rectangular type. You can also obtain StructTypeInfo through an instance.
    let ty = StructTypeInfo.get("test.Rectangular")

    // Obtain the static variable.
    let sv = ty.getStaticVariable("area")
    println(sv)
    return
}

Results:

static area: Int64

static func get(String)

public redef static func get(qualifiedName: String): StructTypeInfo

Description: Obtains StructTypeInfo of the type corresponding to qualifiedName.

Parameters:

  • qualifiedName: String: qualified name of a type

Returns:

  • StructTypeInfo: type information of the Struct type corresponding to qualifiedName

Throws:

Examples:

import std.reflect.*

import std.reflect.*

public struct Rectangular {}

main(): Unit {
    let ty = StructTypeInfo.get("default.Rectangular")
    println(ty)
    return
}

Results:

default.Rectangular

static func of(Any)

public redef static func of(a: Any): StructTypeInfo

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.

Parameters:

  • a: Any: instance of any type

Returns:

  • StructTypeInfo: type information corresponding to the runtime type of instance a

Throws:

Examples:

package test

import std.reflect.*

public struct Rectangular {}

main(): Unit {
    var r = Rectangular()
    let ty = StructTypeInfo.of(r)
    println(ty)
    return
}

Results:

test.Rectangular

static func of<T>()

public redef static func of<T>(): StructTypeInfo

Description: Obtains the type information corresponding to a given T type.

Returns:

Throws:

Examples:

import std.reflect.*

public struct Rectangular {}

main(): Unit {
    let ty = StructTypeInfo.of<Rectangular>()
    println(ty)
    return
}

Results:

default.Rectangular

class TypeInfo

sealed abstract class TypeInfo <: Equatable<TypeInfo> & Hashable & ToString

Description: Provides a common interface for operations on 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 types:

prop annotations

public prop annotations: Collection<Annotation>

Description: Obtains all annotations applied to the type corresponding to TypeInfo and returns the corresponding collection.

NOTE

  • If no annotation is applied to the type 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 in 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 or class, the collection does not contain information about the inherited instance functions.

Type: Collection<InstanceFunctionInfo>

prop instanceProperties

public prop instanceProperties: Collection<InstancePropertyInfo>

Description: Obtains information about all public instance properties in 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 or class, the collection does not contain information about the inherited instance properties.

Type: Collection<InstancePropertyInfo>

prop modifiers

public prop modifiers: Collection<ModifierInfo>

Description: Obtains information about all modifiers in the type corresponding to TypeInfo and returns the corresponding collection.

NOTE

  • If the type has no modifier, an empty collection is returned.
  • The collection does not guarantee a constant traversal sequence.
  • By default, the interface type has the open semantics. Therefore, the returned collection always contains the open 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 corresponding to 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 the std 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 functions in the type corresponding to TypeInfo and returns the corresponding collection.

NOTE

  • If the type corresponding to TypeInfo does not have any public static 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, or interface, the collection does not contain information about the inherited static functions.

Type: Collection<StaticFunctionInfo>

prop staticProperties

public prop staticProperties: Collection<StaticPropertyInfo>

Description: Obtains information about all public static properties in the type corresponding to TypeInfo and returns the corresponding collection.

NOTE

  • If the type corresponding to TypeInfo does not have any public static 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, or interface, the collection does not contain information about the inherited static properties.

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

  • By default, the interface Any type is directly implemented by all types.
  • The collection does not guarantee a constant traversal sequence.
  • Currently, the struct type can only obtain the interface Any type.

Type: Collection<InterfaceTypeInfo>

static func get(String)

public static func get(qualifiedName: String): TypeInfo

Description: Obtains TypeInfo of the type corresponding to qualifiedName.

NOTE

Currently, qualifiedName of a type does not support qualified names of Nothing, function, tuple, and enum types.

Parameters:

  • qualifiedName: String: qualified name of a type

Returns:

  • TypeInfo: type information of the type corresponding to qualifiedName

Throws:

  • InfoNotFoundException: If the type information of the type corresponding to qualifiedName cannot be obtained, this exception is thrown.

Examples:

import std.reflect.*

public class Rectangular {}

main(): Unit {
    let ty = TypeInfo.get("default.Rectangular")
    println(ty)
    return
}

Results:

default.Rectangular

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, the runtime types not supported by instance a include the function type, tuple type, and enum type.

Parameters:

  • a: Any: instance of any type

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.

Examples:

package test

import std.reflect.*

public class Rectangular {}

main(): Unit {
    var r: Any = Rectangular()
    let ty = TypeInfo.of(r)
    println(ty)
    return
}

Results:

test.Rectangular

static func of(Object) (deprecated)

public static func of(a: Object): ClassTypeInfo

Description: Obtains the class type information corresponding to the runtime type of a given instance of the class type.

NOTE

This function will be deprecated in future releases and the static func of(Object) function of ClassTypeInfo will be used instead.

Parameters:

  • a: Object: instance of the class type

Returns:

  • ClassTypeInfo: class type information corresponding to the runtime type of instance a of the class type

Throws:

  • InfoNotFoundException: If the class type information corresponding to the runtime type of instance a cannot be obtained, this exception is thrown.

static func of<T>()

public static func of<T>(): TypeInfo

Description: Obtains the type information corresponding to a given T type.

NOTE

  • Currently, the generic type T does not support the Nothing, function, tuple, or enum type.
  • T supports passing type aliases, including built-in type aliases (such as Int, UInt, and Rune) and user-defined type aliases.

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.

Examples:

import std.reflect.*

public class Rectangular {}

main(): Unit {
    let ty = TypeInfo.of<Rectangular>()
    println(ty)
    return
}

Results:

default.Rectangular

func findAnnotation<T>()

public func findAnnotation<T>(): Option<T>

Description: Attempts to obtain the annotation that is applied to the type 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 the type based on a given function name and a given type information list corresponding to the function parameter type list.

Parameters:

  • name: String: function name
  • parameterTypes: Array<TypeInfo>: type information list corresponding to the function parameter type list

Returns:

Throws:

Examples:

import std.reflect.*

public class Rectangular {
    public var length = 4
    public var width = 5
    public func area(): Int64 {
        return length * width
    }
}

main(): Unit {
    // Obtain TypeInfo through the qualified name of the Rectangular type. You can also obtain TypeInfo through an instance.
    let ty = TypeInfo.get("default.Rectangular")
    // Obtain InstanceFunctionInfo.
    var gif = ty.getInstanceFunction("area")

    println(gif)
    return
}

Results:

func area(): Int64

func getInstanceFunctions(String)

public func getInstanceFunctions(name: String): Array<InstanceFunctionInfo>

Description: Attempts to obtain the information about all matched instance functions in the type based on a given function name.

Parameters:

Returns:

Examples:

import std.reflect.*

public class Rectangular {
    public var length = 4
    public var width = 5
    public func area(): Int64 {
        return length * width
    }
}

main(): Unit {
    // Obtain TypeInfo through the qualified name of the Rectangular type. You can also obtain TypeInfo through an instance.
    let ty = TypeInfo.get("default.Rectangular")
    // Obtain InstanceFunctionInfo.
    var gif = ty.getInstanceFunctions("area")

    println(gif)
    return
}

Results:

[func area(): Int64]

func getInstanceProperty(String)

public func getInstanceProperty(name: String): InstancePropertyInfo

Description: Attempts to obtain information about a matched instance property in the type based on a given property name.

Parameters:

Returns:

Throws:

Examples:

import std.reflect.*

public class Rectangular {
    public var length = 4
    public prop width: Int64 {
        get() {
            5
        }
    }
}

main(): Unit {
    // Obtain TypeInfo through the qualified name of the Rectangular type. You can also obtain TypeInfo through an instance.
    let ty = TypeInfo.get("default.Rectangular")
    // Obtain InstancePropertyInfo.
    var gip = ty.getInstanceProperty("width")

    println(gip)
    return
}

Results:

prop width: Int64

func getStaticFunction(String, Array<TypeInfo>)

public func getStaticFunction(name: String, parameterTypes: Array<TypeInfo>): StaticFunctionInfo

Description: Attempts to obtain information about a matched static function in the type based on a given function name and a given type information list corresponding to the function parameter type list.

Parameters:

  • name: String: function name
  • parameterTypes: Array<TypeInfo>: type information list corresponding to the function parameter type list

Returns:

  • StaticFunctionInfo: If a match is found, the information about the static function is returned.

Throws:

Examples:

package test

import std.reflect.*

public class Rectangular {
    public static func myName(): String { "" }
}

main(): Unit {
    // Obtain TypeInfo through the qualified name of the Rectangular type. You can also obtain TypeInfo through an instance.
    let ty = ClassTypeInfo.get("test.Rectangular")

    // Obtain the static function.
    let sf = ty.getStaticFunction("myName")
    
    println(sf)
    return
}

Results:

static func myName(): String

func getStaticFunctions(String)

public func getStaticFunctions(name: String): Array<StaticFunctionInfo>

Description: Attempts to obtain the information about all matched static functions in the type based on a given function name.

Parameters:

Returns:

Examples:

package test

import std.reflect.*

public class Rectangular {
    public static func myName(): String { "" }
}

main(): Unit {
    // Obtain TypeInfo through the qualified name of the Rectangular type. You can also obtain TypeInfo through an instance.
    let ty = TypeInfo.get("test.Rectangular")

    // Obtain the static function.
    let sf = ty.getStaticFunctions("myName")
    
    println(sf)
    return
}

Results:

[static func myName(): String]

func getStaticProperty(String)

public func getStaticProperty(name: String): StaticPropertyInfo

Description: Attempts to obtain information about a matched static property in the type based on a given property name.

Parameters:

Returns:

  • StaticPropertyInfo: If a match is found, the information about the static property is returned.

Throws:

Examples:

package test

import std.reflect.*

public class Rectangular {
    private static var valueArea = 0
    public static mut prop area: Int64 {
        get() { valueArea }
        set(v) { valueArea = v }
    }
}

main(): Unit {
    // Obtain TypeInfo through the qualified name of the Rectangular type. You can also obtain TypeInfo through an instance.
    let ty = TypeInfo.get("test.Rectangular")

    // Obtain the static property.
    let sp = ty.getStaticProperty("area")
    
    println(sp)
    return
}

Results:

static mut prop area: Int64

func hashCode()

public func hashCode(): Int64

Description: Obtains the hash value of the type information.

NOTE

The internal implementation is to obtain the hash value of the qualified name string in 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 indicated by the TypeInfo instance specified in the parameter.

NOTE

Currently, the interface type implemented by any struct type cannot be obtained. Therefore, false is always returned when it is determined whether a struct is a subtype of an interface.

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.

Examples:

package test

import std.reflect.*

public abstract class Rectangular {}

public class Square <: Rectangular {}

main(): Unit {
    // Obtain TypeInfo through the qualified name of the Rectangular type. You can also obtain TypeInfo through an instance.
    let tyr = ClassTypeInfo.get("test.Rectangular")
    let tys = ClassTypeInfo.get("test.Square")
    println(tys.isSubtypeOf(tyr))
    return
}

Results:

true

func toString()

public func toString(): String

Description: Obtains the type information in string format.

NOTE

The internal implementation is to obtain the qualified name string in 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 information about the other type.

Parameters:

  • that: TypeInfo: information about the other type to be compared with

Returns:

  • Bool: If the qualified name in 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 information about the other type.

Parameters:

  • that: TypeInfo: information about the other type to be compared with

Returns:

  • Bool: If the qualified name in the type information is equal to that, true is returned. Otherwise, false is returned.