UML and SysML to Kotlin - Class Code Generator Specification

This section describes the UML and SysML to Kotlin code generation for structured classes.

This page discusses:

Glossary

Acronym Definition
SPO Software Production Operation
BL Behavior Layer
ML Middleware Layer
BSM Behavior Specific Middleware
TSM Target Specific Middleware

Referenced Documents

Document Internal Reference
Kotlin Code Architecture Specification [1]
UML & SysML to Kotlin - Operation Specification [2]

General Concepts

UML & SysML to Kotlin code generator is an operation generating Kotlin code from UML and SysML design. See [2] for more information.

This specification document is focused on the Kotlin code generation from UML class diagram.

Supported Elements

Here is an exhaustive list of elements used by the code generator to produce the Code with a summary of the purpose and impact.

Element Description
Class Element for which a kotlin file is generated. A Class contains a list of methods and attributes. A class can be a data class or a normal class.
Interface Element for which a kotlin file is generated. An Interface declares a list of methods to be implemented.
Enumeration Element for which a kotlin file is generated. Data type used to define a collection of constants.
Association An Association is a relation between 2 classes. Can be directed or bidirectional. Can be public, protected or private
Aggregation An Aggregation is a kind of association with a meaning of containment. Can be directed or bidirectional. Can be public, protected or private
Composition A Composition means that the root class is composed and another class. Can be directed or bidirectional. Can be public, protected or private
Flow Property A Flow Property is a member of an Interface Block referenced by a Proxy Port and representing a data transmitted via that port. Flow Properties are not yet supported
Generalization A Class can inherit from one and only one class via a generalization relation An Interface can inherit from multiple interfaces.
Interface Realization Relation describing the realization of an interface by classes. A Class can implement multiple interfaces.
Operation There is 2 ways to use the Operation element: 1. Member of a class representing a method. 2. Member of an Interface representing an abstract method.
Property A property can be a member of a class or an interface representing an attribute. Can be public, protected, private or internal.
Classifier Behavior A behavior can be a statemachine, an activity or an opaque behavior. The behavior can be in a class itself and attached to an operation. not yet supported
Interface Block Element describing elements transmitted through a Proxy Port element not yet supported

Validation Constraints

About Validation Constraints

Generator Behavior: Nested classes are ignored.

Generator Behavior: Operations with same signature as an attribute’s setter or getter are not generated.

Generator Behavior: Attributes or operations which are private and abstract are generated as non-abstract.

Generator Behavior: Attributes and operations which are private and open (i.e. not final) are generated as final.

Generator Behavior: Attributes or operations which open and declared inside a final class are generated as final.

Generator Behavior: Top-level classes, interfaces and enumerations with visibility protected are generated with visibility public.

Generator Behavior: Non-static mutable private attributes of interface are generated with visibility public.

Generator Behavior: Non-static protected or internal attributes of interface are generated with visibility public.

Generator Behavior: Non-static internal or protected operations in interface are generated with visibility public.

Generator Behavior: Protected argument of constructor are generated with visibility public or with the visibility of the corresponding attribute if one is defined and different of protected.

Code Generator Specification

This section is divided in 2 parts:

  • The generated files specification
  • The behavior specification

Files Specifications

Code generator generates one kotlin file for each element which can be a UML class, a UML interface or a UML enumeration:

  • <ClassName>.kt
  • <InterfaceName>.kt
  • <EnumerationName>.kt

General requirements related to file content are described in [1].

<ObjectName>.kt

<ClassName>.kt, <InterfaceName>.kt and <EnumerationName>.kt are described in the same way. For the following chapter: ClassName, InterfaceName and EnumerationName are replaced by ObjectName which points to the name of the Class or the Interface or the Enumeration.

<ObjectName>.kt file describes the content of a class entity. This file declares and implements the elements associated to a class.

File <ObjectName>.kt is generated for the each UML class / UML interface / UML Enumeration element involved in the code generation.

The file name <ObjectName>.kt matches the name of the element.

File is generated in a folder reflecting the structure of package of the UML project.

Kotlin folder hierarchy

The package in which the file is generated is declared on top of file after the header.

package root.model

Example: package declaration

Import of other classes, Interfaces, enumerations on which the current class depends (based on relations such as - inheritance, composition, aggregation) - are generated if any.

import root.model.datasource

Example: Imports declaration

See chapter Semantic Code Specifications for more details.

The class is described using the regular kotlin declaration mechanism.

/**
 * @generated_from <class uiid>
 */ 
class LockManager {

  <MEMBERS DECLARATION – See chapter Semantic Code Specifications>

}

Example: Class declaration

The interface is described using the regular kotlin declaration mechanism.

/**
 * @generated_from <interface uiid>
 */ 
interface MyInterface {

  <MEMBERS DECLARATION – See chapter Semantic Code Specifications>

}

Example: Interface declaration

The enumeration is described using the regular kotlin declaration mechanism.

See the dedicated section in chapter Semantic Code Specifications.

/**
 * @generated_from <enumeration uiid>
 */ 
enum class MyEnum {

  <MEMBERS DECLARATION – See chapter Semantic Code Specifications>

}

Example: Enumeration declaration

The visibility of an ObjectName is used as declared in the model. The default visibility is public, which can be explicitly represented by the public keyword or left blank.

Semantic Code Specifications

This section describes the behavior of the code generator depending on the UML element.

Package

In Kotlin, a package is a logical grouping of classes, interfaces, and enumerations that are related to each other.

The concept of "visibility of a package" does not exist in Kotlin.

Package Declaration

When ObjectName is created within a hierarchy of packages, This hierarchy is declared on the top of the file using the package statement.

package package_name.sub_package_1.sub_package_2
/**
 * @generated_from <class uuid> 
*/
class A

Example: Declaration of a package hierarchy

Class

If generalization relation is created from a class to another one, then this inheritance relation is reproduced in class declaration.

Class declaration with generalization

/** @generated from: <class uuid> */
class A : B()

Example: Class declaration with generalization

Abstract class

Abstract classes cannot be instantiated directly; they serve as blueprints for subclasses to inherit and provide implementations for their abstract methods.

If the isAbstract attribute of the class is set to true, then the class is generated as an abstract class by adding the keyword abstract to the class declaration.

/** @generated from: <class uuid> */
abstract class A {

  /**Abstract method*/
  abstract fun method()
}

Example: Abstract class

An open class is a class that can be sub-classed or extended. Kotlin classes are final by default, meaning they cannot be sub-classed unless explicitly marked as open.

If the isLeaf or isFinalSpecialization attribute of the class is set to false, then the class is generated as an open class.

/**
 * @generated_from <class uuid> 
 */
open class A

Example: Open class

Data class

If a class is not abstract, open, sealed, or inner, AND has at least one property in the primary constructor, AND does not override equals(), hashCode(), toString(), or copy(), AND does not extend another class, then it is generated as a data class.

A data class is designed to hold data and provides automatically functions like equals, hashCode, toString, copy, and componentN.

/**
 * @generated_from <class uuid> 
 */
data class A(name: String, age:Int)

Example: Data class

Composition relation (black diamond)

Not directional composition relation

Directional composition relation

If a composition relation is created from a class to another one as directional or not directional, a variable is created in the source class of relation to point to target class.

If a composition relation is created from a class to another one as not directional, a variable is created in the target class of relation to point to the source class.

class A {
    /**
     * @brief Attribute for composition relation to B:b
     * @generated_from <property uuid>
     */
    private val b:B
}

Example: variable in source class for directional and not directional relation

class B {
    /**
     * @brief Attribute for aggregation relation to A:a
     * @generated_from <property uuid>
     */
    private val a:A
}

Example: variable in target class for not directional relation

Aggregation relation (white diamond)

Not directional aggregation relation

If an aggregation relation is created from a class to another one as directional or not directional, a variable is created in the source class of relation to point to target class.

If an aggregation relation is created from a class to another one as not directional, a variable is created in the target class of relation to point to the source class.

class A {
    /**
     * @brief Attribute for association relation to B:b
     * @generated from <property uuid>
     */
     val b:B
}

Example: Variable in source class

class B {
    /**
     * @brief Attribute for aggregation relation to A:a
     * @generated from <property uuid>
     */
    val a:A
}

Example: Variable in target class for not directional relation

Association relation

Association relation

If an association relation is created between 2 classes, a variable is created in each class to point to the other class.

class A {
    /**
     * @brief Attribute for association relation to B:b
     * @generated from <property uuid>
     */
    val b:B
}

class B {
    /**
     * @brief Attribute for association relation to A:a
     * @generated from <property uuid>   
       */
    val a:A
}

Example: Association between 2 classes

Realization relation

Interface realization

If realization relation is created from an UML class to one or multiple UML interfaces, then the generated class will implement the targeted Interfaces.

/** @generated from: <class uuid> */
class A : B,C {
}

Example: Class declaration with realization

If interface realization relation is created from an UML class to one or multiple UML interfaces, then the generated class will implement the targeted Interfaces.

Operations without implementation in targeted interface will be overridden in the class implementing this interface.

Interface operation in the model

/** @generated from: <interface uuid> */
Interface B {
  fun getNumber():Int
}

Example: Interface operation

/** @generated from: <class uuid> */
class A : B  {
  override fun getNumber():Int{
    return 0
  }
}

Example: Overridden an operation without implementation

If an operation of the targeted interface has the same name and parameters as an operation in the class implementing this interface, and this operation has an implementation in the interface, the method will be generated with the override keyword.

Note that implementation is not yet detected by code generator.

If a Property of the targeted UML Interface has no default value, the property will be overridden in the class implementing this interface.

If a Property of the targeted UML Interface has a default value, the property will NOT be overridden in the class implementing this interface.

If a Property of the targeted UML Interface has the same name than a property in the class implementing this interface, the property will be generated with override keyword.

/**
 * class MyClass
 * @generated_from <class uuid>
 */
Class MyClass : ContactOperations{
  /**
   * @generated_from <property uuid>
   */
  Override val absProperty:String=”init_value”

  /**
   * @generated_from <property uuid>
   */
  Override itfProperty:String
    get()=super.itfProperty


  /**
   * @generated_from <operation uuid>
   */
  override add(contact /*in*/ : Contact):Contact{
    /* BEG_USER_CODE(<operation uuid>) do not remove */
    // Add your code here
    return contact 
    /* END_USER_CODE(<operation uuid>) do not remove */
  }
}

Example: Class implementing interface

Substitution relation

Substitution relation is not supported.

Dependency relation

When there is a dependency relationship between two objects (UML classes or UML interfaces), an import statement for to the targeted object by the relation is generated in the source object file.

Interface

Methods declared in the UML Interface are generated in the interface without any body.

Properties declared in the UML Interface are generated in the interface.

If a Property of the UML Interface is mutable i.e. is not read only, the property is generated as abstract

If a Property of the UML Interface is immutable i.e. is read only and has no default value, the property is generated as abstract

If a Property of the UML Interface is immutable i.e. is read only and has default value, the property is generated as abstract and the default value is declared via a getter.

Note that no custom setter can be generated for a Property.

If a Method of the UML Interface is private and not static, a body is generated with expected returned value type

If a method of the UML Interface is private, internal or public and static, a body is generated with expected returned value type

/**
 * interface ContactOperations
 * @generated_from <interface uuid>
 */
interface ContactOperations{

  /**
   * @generated_from <property uuid>
   */
  val absProperty:String


  /**
   * @generated_from <property uuid>
   */
  val itfProperty:Boolean
    get()=true

  /**
   * add absMethod
   * @generated_from <operation uuid>
   */
  absMethod (contact /*in*/ : Contact):Contact

  /**
   * add method
   * @generated_from <operation uuid>
   */
  method (contact /*in*/ : Contact):Contact?{
    /* BEG_USER_CODE(<operation uuid>) do not remove */
    // Add your code here
    return null 
    /* END_USER_CODE(<operation uuid>) do not remove */

  }
}

Example: Interface methods declaration

Enumeration

Enumeration is a special data type that allows a variable to be a set of predefined constants.

Enumeration datatype

Enumeration is generated via the standard Kotlin mechanism to generate enums.

/** 
* @generated_from <enumeration uuid>
*/
enum class Group {
  /**
  * @generated_from <litteral uuid>
  */
  FAMILY,
  /**
  * @generated_from <litteral uuid>
  */
  FRIEND,
  /**
  * @generated_from <litteral uuid>
  */
  COLLEAGUE,
  /**
  * @generated_from <litteral uuid>
  */
  UNKNOWN
}

Example: Enumeration declaration

Property

Property declaration in class

Each property declared in a UML Class is replicated in the generated code.

A brief description is generated for any property describing type and name of the variable.

Additional documentation is generated if the documentation section is field in the model.

UML Primitive type of the property is converted to an Object type. See following table.

Uml type Object Type in Kotlin
byte Byte
character Char
Integer, int Int
Boolean, boolean Boolean
short Short
long Long
float Float
double, Real Double
String String

The visibility of a property is used as declared in the model. The default visibility is public, which can be explicitly represented by the public keyword or left blank.

Default value is set as declared in the model.

/**
 * This is my documentation for attribute
 * @brief Attribute for String:attribute
 * @generated_from <property uuid>
 */
var attribute: String = “attr”

Example: Property

Final declaration

If the isReadOnly attribute of the property is set to true, the property is marked as val, making it immutable.

If the isReadOnly attribute of the property is set to false, the property is marked as var, making it mutable.

/**
 * @brief Attribute for String: attribute
 * @generated_from <property uuid>
 */
val readOnlyValue: String = “defaultValue”

/**
 * @brief Attribute for String:attribute
 * @generated_from <property uuid>
 */
var writtableVariable: String = ”abc”

Example: var and val declaration

Static declaration

A static property belongs to the class itself rather than to any specific instance of the class and it can be accessed directly using the class name. This concept is supported by the companion object.

A companion object is created if the class or the interface contains at least one static property.

If the isStatic attribute of the property is set to true, the property will be declared in the companion object of the class.

companion object {
    /**
     * @brief Attribute for String:attribute
    * @generated_from <property uuid>
    */
    private val attribute: String = ”value”

}

Example: companion object

Array declaration

If the multiplicity corresponds to a finite number or an interval of finite numbers, an array is created with a length equal to the upper value.

If the multiplicity corresponds to a finite number or an interval of finite numbers and the type of the property is one of the following table, a native array is used a described in the table.

Uml type Native array in Kotlin
Array of byte ByteArray
Array of short ShortArray
Array of int IntArray
Array of long LongArray
Array of float FloatArray
Array of double DoubleArray
Array of char CharArray
Array of boolean BooleanArray
Property with [10] multiplicity

/**
 * @generated_from <property uuid>
 */
var number : IntArray? = IntArray(10)

Example: Array declaration for native array types

If the multiplicity corresponds to a finite number or an interval of finite numbers and the type of the property is different of the table above, a generic array declaration is used.

/**
 * @generated_from <class uuid>
 */
class myClass

/**
 * @generated_from <property uuid>
 */
var myVar : Array<myClass?> = arrayOfNulls(10)

Example: Array declaration for a user type

If an array is expected to be created according to above requirement, a default value is generated as in the model.

Empty Array in model

/**
 * @generated_from < property uuid>
 */
 val a: Array<Int?> = emptyArray()

Example: Declaration of an attribute with an empty array

Array with a value in the model

/**
 * @generated_from <operation uuid>
 */
 Val a: Array<Int?> = arrayOf(1,2,3,4) 

Example: Declaration of an attribute with an initialized array

Immutable List declaration
Property with * multiplicity

If the multiplicity is equal to "*", isUnique attribute is not set or set to false, a List is created.

If a List is expected to be created according to above requirement and isReadOnly is set to true an immutable List is created.

If a Immutable List is expected to be created according to above requirement, a default value is generated as in the model.

/**
 * @generated_from <property uuid>
 */
val emailAddress: List<String?> = emptyList()

Example: Kotlin Immutable List declaration without default value

Empty Collection in model

/**
 * @generated_from <property uuid>
 */
val emailAddress: List<String?> = emptyList()

Example: Empty Kotlin Immutable List declaration

Immutable List in model

/**
 * @generated_from <property uuid>
 */
val emailAddress:List<String?> = listOf(“a”,”b”,”c”,”d”)

Example: Kotlin Immutable List declaration with default value

Mutable List declaration

If a List is expected to be created according to above requirement and isReadOnly is set to false a mutable List is created.

If a Mutable List is expected to be created according to above requirement, a default value is generated as in the model.

Import java.util.List
/**
 * @generated_from <property uuid>
 */
var emailAddress: List<String?> = mutableListOf()

Example: Kotlin mutable List declaration

Empty Collection in model

/**
 * @generated_from <property uuid>
 */
var emailAddress:List<String?> = mutableListOf()

Example: Empty mutable List declaration

Mutable List in model

/**
 * @generated_from <property uuid>
 */
var emailAddress:List<String?> = mutableListOf(“a”,”b”,”c”,”d”)

Example: Mutable list declaration

If a List is used according to the above requirements, no import is needed.

Immutable Set declaration

If the multiplicity is equal to "*", isOrdered is set to false or not set and isUnique is set to true, a Set is created.

If a Set is expected to be created according to above requirement and isReadOnly is set to true, an immutable Set is created.

If an Immutable Set is expected to be created according to above requirement, a default value is generated as in the model.

/**
 * @generated_from <property uuid>
 */
val emailAddress: Set<String?> = emptySet()

Example: Kotlin Immutable Set declaration

Empty Set in model

/**
 * @generated_from <property uuid>
 */
val emailAddress: Set<String?> = emptySet()

*Example: Empty Immutable Set declaration

Immutable Set in model

/**
 * @generated_from <property uuid>
 */
val emailAddress: Set<String?> = setOf(“a”,”b”,”c”,”d”)

Example: Immutable Set declaration

Mutable Set declaration

If a Set is expected to be created according to above requirement and isReadOnly is set to false a mutable Set is created.

If a Mutable Set is expected to be created according to above requirement, a default value is generated as in the model.

Import java.util.List
/**
 * @generated_from <property uuid>
 */
var emailAddress: Set<String?> = mutableSetOf()

Example: mutable Set declaration

Empty mutable Set in model

/**
 * @generated_from <property uuid>
 */
var emailAddress: Set<String?> = mutableSetOf()

Example: Empty mutable Set declaration

Mutable Set in model

/**
 * @generated_from <property uuid>
 */
var emailAddress:MutableSet<String?> = mutableSetOf(“a”,”b”,”c”,”d”)

Example: mutable set declaration

If a Set is used according to the above requirements, no import is needed.

Immutable Sorted Set declaration

If a Sorted Set is expected to be created according to above requirement and isReadOnly is set to true, an immutable Sorted Set is created.

If an Immutable Sorted Set is expected to be created according to above requirement, a default value is generated as in the model.

/**
 * @generated_from <property uuid>
 */
val emailAddress: Set<String?> = linkedSetOf()

Example: Kotlin immutable Sorted Set declaration

Empty immutable Sorted Set in model

/**
 * @generated_from <property uuid>
 */
val emailAddress: Set<String?> = linkedSetOf("a", "b", "c", "d")

Example: Immutable Sorted Set declaration

Mutable Sorted Set declaration

If the multiplicity is equal to "*", isOrdered is set to true and isUnique is set to true, a Sorted Set is created.

If a Sorted Set is expected to be created according to above requirement and isReadOnly is set to false, a mutable Sorted Set is created.

If a mutable Sorted Set is expected to be created according to above requirement, a default value is generated as in the model.

Empty Sorted Set in model

/**
 * @generated_from <property uuid>
 */
var emailAddress: Set<String?> = mutableSetOf ()

Example: mutable empty java Sorted Set declaration

Non empty Sorted Set in model

/**
 * @generated_from <property uuid>
 */
var emailAddress: Set<String?> = mutableSetOf("a", "b", "c", "d")

Example: mutable non-empty Sorted Set declaration

Operation

Operation declaration in class

Each operation declared in a UML Class or UML Interface is generated within their body.

Operations are declared using the keyword fun.

A brief description is generated for any property describing type and name of the variable.

Additional documentation is generated if the documentation section is field in the model.

Visibility of the operation is used as declared in the model. The default visibility is public, which can be explicitly represented by the public keyword or left blank.

In the context of an UML Class, user code section is inserted in operation to let the user fills his behavior.

If any, a default return code is inserted in the user code section.

/**
 * @generated_from <operation uuid>
 */
fun lockDoors():Boolean {
    /* BEG_USER_CODE<operation uuid>) do not remove */
    // Add your code here
    return true
    /* END_USER_CODE(<operation uuid>) do not remove */
}

Example: Operation

Constructor

Constructor methods are only generated when explicitly declared in UML Class.

If an operation has the same name as the class, it is considered a constructor of the class.

If all the arguments of a constructor match with existing properties in the class, such constructor can be considered as primary constructor.

If multiple constructors can be considered as primary constructors in an UML class, the one containing the biggest number of arguments is generated as primary constructor.

Note that the primary constructor in Kotlin is declared in the class header.

The properties contained in the primary constructor are not generated in the class body but in the constructor declaration according to Kotlin syntax.

If multiple constructors exist in a UML class, constructors not considered as primary constructor are generated as secondary constructors. These constructors use constructor keyword, call the primary constructor, and have a body.

In secondary constructor, if operation arguments have the same name as the class attributes, the assignment of the value is generated.

class Door(private val attr:String){

    /**
     * @brief Constructor of Door class
     * @generated from  <operation uuid>
     */ 
    Constructor():this(“initialvalue”) {
        /* BEG_USER_CODE(<operation uuid>) do not remove */
        // Add your code here
        /* END_USER_CODE(<operation uuid>) do not remove */
    }
}

Example: Constructor

If the secondary constructor has the same parameters as the primary constructor, these parameters are passed to the primary constructor using this keyword followed by the parameter names. Otherwise, explicit values or additional parameters must be provided to call the primary constructor.

class Door(val attr:String=”initialvalue”){

    /**
     * @brief Constructor
     * @generated_from < operation uuid>
     */
    constructor (attr:String, a:Int):this(“initailvalue”) {
        /* BEG_USER_CODE(<operation uuid>) do not remove */
        /* Add your code here */
        /* END_USER_CODE(<operation uuid>) do not remove */
    }
}

Example: Constructors with different parameters

Getter and Setter

In Kotlin, it is not recommended to write explicit getters and setters for all attributes. Kotlin provides properties that automatically generate default getters and setters to reduce boilerplate code and improve readability.

Code generator does not generate any getter and setter.

Static declaration

A static operation belongs to the class itself rather than to any specific instance of the class and it can be accessed directly using the class name. This concept is supported by the companion object.

See REQ_UML_CLS_KOTLIN_92129 for the companion object creation.

If the isStatic attribute of the operation is set to true, the operation is declared in the companion object of the class.

Companion object {
    /**
     * @generated_from <operation uuid>
     */
    fun get():Int {
        /* BEG_USER_CODE(<operation uuid>) do not remove */
        /* Add your code here */
        return 0
        /* END_USER_CODE(<operation uuid>) do not remove */
    }
}

Example: static function

Final declaration

By default, all functions in Kotlin are final.

If the isLeaf attribute is set to false for a method, then the method is generated as an open method.

/**
 * @generated_from <operation uuid>
 */
open fun getAge():Int?{
    /* BEG_USER_CODE(<operation uuid>) do not remove */
    /* Add your code here */
    return 0
    /* END_USER_CODE(<operation uuid>) do not remove */
}

Example: open method

/**
 * @generated_from <operation uuid>
 */
fun finalFunction():Boolean {
    /* BEG_USER_CODE(<operation uuid>) do not remove */
    /* Add your code here */
    return true
    /* END_USER_CODE(<operation uuid>) do not remove */
}

Example: final method

Abstract declaration

An abstract method is a method declared without any implementation.

If the isAbstract attribute of the operation is set to true, method is generated as abstract by adding the keyword abstract to the method declaration.

/**
 * @generated_from <operation uuid>
 */
abstract fun function():Unit

Example: abstract method

Exception

Exception not yet supported.

Operation behavior

If an operation has an Opaque behavior assigned to it, then this opaque behavior is replicated in the operation body. Not yet supported

Parameter

Type of parameter of operation with direction set as return is used as return type of the operation.

Type of the parameter is used as declared in the model.

Default Value of the parameter is used as declared in the model.

The parameter of operation with the direction set as "in", "out", or "inout" is used as a parameter of the operation,

Direction in or out or inout of parameter is used for documentation purpose.

Note that parameters direction do not have any meaning in Kotlin.

Note that parameters do not support Visibility. Parameters defined in regular functions are local to that function and are not accessible outside it.

/**
 * @generated_from <operation uuid>
 */
fun setWindowPosition(windowPosition: ControlEnum):Boolean{
    return true
}

Example: Kotlin function parameter

Array declaration
Parameter with finite multiplicity

If the multiplicity corresponds to a finite number or an interval of finite numbers, an array is created.

If the multiplicity corresponds to a finite number or an interval of finite numbers and the type of the property is one of the following table, a native array is used a described in the table.

UML type Native array in Kotlin
Array of byte ByteArray
Array of short ShortArray
Array of int IntArray
Array of long LongArray
Array of float FloatArray
Array of double DoubleArray
Array of char CharArray
Array of boolean BooleanArray
/**
 * @generated_from <operation uuid>
 */
fun calculate (a: IntArray?): Double {}

Example: Array declaration for a native type parameter

If the multiplicity corresponds to a finite number or an interval of finite numbers and the type of the parameter is different of the table above, a generic array declaration is used.

/**
 * @generated_from <operation uuid>
 */
fun calculate (a: Array<myClass>?): Double {
    return 0.0
}

Example: Array declaration for a user type parameter

If an array is expected to be created according to above requirement and the default value is () or {}, an empty array is created.

Empty array in model

/**
 * @generated_from <operation uuid>
 */
fun getResult (a: Array<Int?> = emptyArray()): Int {
    return 0
}

Example: Declaration of a parameter with an empty array

If an array is expected to be created according to above requirement and the default value is not empty inside () or { }, a non empty array is created.

Array with a value in the model

/**
 * @generated_from <operation uuid>
 */
fun do (a: Array<Int?> = arrayOf(1,2,3,4)): Int {  
    return 0;
}

Example: Declaration of a parameter with an initialized array

List declaration
Parameter with * multiplicity

As Kotlin supports functional programming paradigms, it is considered good practice not to modify function parameter values. In accordance with this principle, the Kotlin code generator generates only immutable parameters for list types (i.e., uses List<T> rather than MutableList<T>)

If the multiplicity is equal to "*", isUnique attribute is set to false, an immutable List is created.

If a List is expected to be created according to above requirement, a default value is generated as in the model.

/**
 * @generated_from <operation uuid>
 */
fun getResult(a: List<Int?>): Int{
    return 0;
}

Example: Declaration of a parameter's List type

Empty Collection in model

/**
 * @generated_from <operation uuid>
 */
fun getResult(a: List<Int?> = emptyList()): Int{
    return 0;
}

Example: Declaration of a parameter with an empty List

Immutable List in model

/**
 * @generated_from <operation uuid>
 */
fun getResult(a: List<Int?> = listOf(1,2,3,4,5,6,7)): Int{
    return 0
}

Example: Declaration of a parameter as an immutable list

If a List is used according to the above requirements, no import is needed.

Set declaration
Parameter with * multiplicity

As Kotlin supports functional programming paradigms, it is considered good practice not to modify function parameters. In accordance with this principle, the Kotlin code generator generates only immutable parameters for set types (i.e., uses Set<T> rather than MutableSet<T>).

If the multiplicity is equal to "*", isOrdered is set to false or not set and isUnique is set to true, an immutable Set is created.

If a Set is expected to be created according to above requirement, a default value is generated as in the model.

/**
 * @generated_from <operation uuid>
 */
fun getResult(a: Set<Int?>): Int{
    return 0
}

Example: Declaration of a parameter’s Set type

Empty Collection in model

/**
 * @generated_from <operation uuid>
 */
fun getResult(a: Set<Int?> = emptySet()): Int{
    return 0
}

Example: Declaration of a parameter with an empty Immutable Set

Immutable Set in model

/**
 * @generated_from <operation uuid>
 */
fun getResult(a: Set<Int>=setOf(1,2,3,4,5,6,7)): Int{
    return 0
}

Example: Declaration of a parameter as an immutable Set

If a Set is used according to the above requirements, no import is needed.

SortedSet declaration
Parameter with * multiplicity

If the multiplicity is equal to "*", isOrdered is set to true and isUnique is set to true, a Set is created.

If a Set is expected to be created according to above requirement, a default value is generated as in the model.

/**
 * @generated_from <operation uuid>
 */
fun getResult(a: Set<Int?>): Int{
    return 0
}

Example: Parameter’s Immutable SortedSet type declaration

Empty Collection in model

/**
 * @generated_from <operation uuid>
 */
fun getResult(a: SortedSet<Int>=Collections.unmodifiableSortedSet(TreeSet()))): Int{
    return 0
}

Example: Declaration of a parameter as an immutable empty Sorted Set

Immutable List in model

/**
 * @generated_from <operation uuid>
 */
fun getResult(a: Set<Int>= Collections.unmodifiableSortedSet(TreeSet(sortedSetOf(1, 2, 3, 4, 5, 6, 7)))) :Int{
    return 0
}

Example: Declaration of an initialized parameter as an immutable SortedSet