Reflection capabilities in MuranoPL.¶
Reflection provides objects that describes MuranoPL classes and packages.
The first important function is typeinfo . Usage:
$typeInfo: typeinfo($someObject)
Now $typeInfo variable contains instance of type of $someObject (MuranoClass instance).
MuranoPL provide following abilities to reflection:
Types¶
| Property | Description | 
|---|---|
| 
 | name of MuranoPL class | 
| 
 | version (SemVer) of MuranoPL class. | 
| 
 | list of class ancestors | 
| 
 | list of class properties. See Properties | 
| 
 | package information. See Packages | 
| 
 | list of methods. See Methods | 
| 
 | reference to type, which can be used as argument in engine functions | 
Example
- $typeInfo: typeinfo($)
...
# log name, version and package name of this class
- $log.info("This is "{class_name}/{version} from {package}",
     class_name => $typeInfo.name,
     version => str($typeInfo.version),
     package => $typeInfo.package.name))
- $log.info("Ancestors:")
- For: ancestor
  In: $typeInfo.ancestors
  Do:
    #log all ancestors names
    - $log.info("{ancestor_name}", ancestor_name => $ancestor.name)
# log full class version
- $log.info("{version}", version => str($typeInfo.version))
# create object with same class
- $newObject = new($typeInfo.type)
Properties¶
Property introspection¶
| Property | Description | 
|---|---|
| 
 | name of property | 
| 
 | boolean value. True, if property has default value, False otherwise | 
| 
 | Usage property’s field. See Property usage for details | 
| 
 | type - owner of declared property | 
Property access¶
| Methods | Description | 
|---|---|
| 
 | set value of  | 
| 
 | get value of  | 
Example
- $typeInfo: typeinfo($)
...
# select first property
- $selectedPropety: $typeInfo.properties.first()
# log property name
- $log.info("Hi, my name is {p_name}, p_name => $selectedProperty.name)
# set new property value
- $selectedProperty.setValue($, "new_value")
# log new property value using reflection
- $log.info("My new value is {value}", value => $selectedProperty.getValue($))
# also, if property static, $target can be null
- $log.info("Static property value is {value},
    value => $staticProperty.getValue(null))
Packages¶
| Property | Description | 
|---|---|
| 
 | list of types, declared in package | 
| 
 | package name | 
| 
 | package version | 
Example
- $typeInfo: typeinfo($)
...
- $packageRef: $typeInfo.package
- $log.info("This is package {p_name}/{p_version}",
    p_name => $packageRef.name,
    p_version => str($packageRef.version))
- $log.info("Types in package:")
- For: type_
  In: $packageRef.types
  Do:
    - $log.info("{typename}", typename => type_.name)
Methods¶
Methods properties¶
| Property | Description | 
|---|---|
| 
 | method’s name | 
| 
 | type - owner of declared method | 
| 
 | list of method’s arguments. See Method arguments | 
Method invoking¶
| Methods | Description | 
|---|---|
| 
 | call  | 
Example
- $typeInfo: typeinfo($)
...
# select single method by name
- $selectedMethod: $typeInfo.methods.where($.name = sampleMethodName).single()
# log method name
- $log.info("Method name: {m_name}", m_name => $selectedMethod.name)
# log method arguments names
- For: argument
  In: $selectedMethod.arguments
  Do:
     - $log.info("{name}", name => $argument.name)
# call method with positional argument 'bar' and named `baz` == 'baz'
- $selectedMethod.invoke($, 'bar', baz => baz)
Method arguments¶
| Property | Description | 
|---|---|
| 
 | argument’s name | 
| 
 | True if argument has default value, False otherwise | 
| 
 | method - owner of argument | 
| 
 | argument’s usage type. See Method arguments for details | 
- $firstArgument: $selectedMethod.arguments.first()
# store argument's name
- $argName: $firstArgument.name
# store owner's name
- $methodName: $firstArgument.declaringMethod.name
- $log.info("Hi, my name is {a_name} ! My owner is {m_name}",
    a_name => $argName,
    m_name => $methodName)
