|
{# --- macro definitions --- #} |
|
|
|
{# --- Variables --- #} |
|
{% macro Variables type %} |
|
{% for variable in type.variables where not variable.isStatic and not variable.typeName|contains:"(" %} |
|
{% call Variable variable %} |
|
{% endfor %} |
|
{% endmacro %} |
|
{# --- outputs --- #} |
|
{% macro Variable variable %} |
|
{% call VariableVisibility variable %}{% call VariableTypeName variable.typeName.name %} {{ variable.name }} |
|
{% endmacro %} |
|
{% macro VariableVisibility target %}{% if target.readAccess == "private" %}-{% elif target.readAccess == "fileprivate" %}-{% else %}+{% endif %}{% endmacro %} |
|
{% macro VariableTypeName typeName %}{% set tmp1 %}{% call PrefixFirst typeName "{" %}{% endset %}{{ tmp1|replace:"!","" }}{% endmacro %} {# work-around for variables with initializer in oneline #} |
|
|
|
{# --- Methods --- #} |
|
{% macro Methods type %} |
|
{% for method in type.methods where not method.isInitializer and not method.isStatic and not method.isClass %} |
|
{% call Method method %} |
|
{% endfor %} |
|
{% endmacro %} |
|
{# --- outputs --- #} |
|
{% macro Method method %} |
|
{% call MethodVisibility method %}{% call MethodName method %} {{ method.returnType.name }} |
|
{% endmacro %} |
|
{% macro MethodVisibility target %}{% if target.accessLevel == "private" %}-{% elif target.accessLevel == "fileprivate" %}-{% else %}+{% endif %}{% endmacro %} |
|
{% macro MethodName method %}{{ method.selectorName }}{% if method.parameters.count == 0 %}(){% endif %}{% endmacro %} |
|
|
|
{# --- Relationships --- #} |
|
{% macro ClassRelationships type %} |
|
{% for basedTypeName, basedType in type.basedTypes %} |
|
{% if basedType.kind == 'protocol' %} |
|
{% call Realization basedType.name type.name %} |
|
{% else %} |
|
{% call Inheritance basedType.name type.name %} |
|
{% endif %} |
|
{% endfor %} |
|
{% call CompositionRelationships type %} |
|
{% call AggregationRelationships type %} |
|
{# {% call AssociationRelationships type %} #} |
|
{% endmacro %} |
|
{% macro ProtocolRelationships type %} |
|
{% for basedTypeName, basedType in type.basedTypes %} |
|
{% call Inheritance basedType.name type.name %} |
|
{% endfor %} |
|
{% call CompositionRelationships type %} |
|
{% call AggregationRelationships type %} |
|
{# {% call AssociationRelationships type %} #} |
|
{% endmacro %} |
|
{% macro CompositionRelationships type %} |
|
{% for variable in type.variables %} |
|
{% if variable.type.name %} |
|
{% call Composition type.name variable.type.name %} |
|
{% endif %} |
|
{% endfor %} |
|
{% endmacro %} |
|
{% macro AggregationRelationships type %} |
|
{% for variable in type.variables %} |
|
{# --- Closure --- #} |
|
{% if variable.typeName|contains:"(" %} |
|
{# nop #} |
|
{# --- Dictionary --- #} |
|
{% elif variable.typeName|contains:":" %} |
|
{% set element %}{% call SugarDictionaryValueElement variable.typeName %}{% endset %} |
|
{% set elementFormatted %}{% call FormatClassName element %}{% endset %} |
|
{% call Aggregation type.name elementFormatted %} |
|
{% elif variable.typeName|contains:"Dictionary<" %} |
|
{% set element %}{% call DictionaryValueElement variable.typeName %}{% endset %} |
|
{% set elementFormatted %}{% call FormatClassName element %}{% endset %} |
|
{% call Aggregation type.name elementFormatted %} |
|
{# --- Array --- #} |
|
{% elif variable.typeName|contains:"[" %} |
|
{% set element %}{% call SugarArrayElement variable.typeName %}{% endset %} |
|
{% set elementFormatted %}{% call FormatClassName element %}{% endset %} |
|
{% call Aggregation type.name elementFormatted %} |
|
{% elif variable.typeName|contains:"Array<" %} |
|
{% set element %}{% call ArrayElement variable.typeName %}{% endset %} |
|
{% set elementFormatted %}{% call FormatClassName element %}{% endset %} |
|
{% call Aggregation type.name elementFormatted %} |
|
{# --- Set --- #} |
|
{% elif variable.typeName|contains:"Set<" %} |
|
{% set element %}{% call SetElement variable.typeName %}{% endset %} |
|
{% set elementFormatted %}{% call FormatClassName element %}{% endset %} |
|
{% call Aggregation type.name elementFormatted %} |
|
{% endif %} |
|
{% endfor %} |
|
{% endmacro %} |
|
{% macro AssociationRelationships type %} |
|
{% for method in type.methods %} |
|
{% for parameter in method.parameters %} |
|
{% if parameter.type.name %} |
|
{% call Association type.name parameter.type.name %} |
|
{% endif %} |
|
{% endfor %} |
|
{% endfor %} |
|
{% endmacro %} |
|
{# --- outputs --- #} |
|
{% macro Inheritance basedType typeName %} |
|
{% call FormatClassName basedType %} <|-- {% call FormatClassName typeName %} : inheritance |
|
{% endmacro %} |
|
{% macro Realization basedType typeName %} |
|
{% call FormatClassName basedType %} <|.. {% call FormatClassName typeName %} : realization |
|
{% endmacro %} |
|
{% macro Composition subject target %} |
|
{% call FormatClassName subject %} *-- {% call FormatClassName target %} : composition |
|
{% endmacro %} |
|
{% macro Aggregation subject target %} |
|
{% call FormatClassName subject %} o-- {% call FormatClassName target %} : aggregation |
|
{% endmacro %} |
|
{% macro Association subject target %} |
|
{% call FormatClassName subject %} --> {% call FormatClassName target %} : association |
|
{% endmacro %} |
|
|
|
{# --- Helpers --- #} |
|
{% macro SugarDictionaryValueElement target %}{% for element in target|replace:"",""|split:":" %}{{ element|replace:"[",""|replace:"]",""|replace:"<","~"|replace:">","~" if forloop.last }}{% endfor %}{% endmacro %} |
|
{% macro DictionaryValueElement target %}{% for element in target|replace:"Dictionary<",""|replace:">",""|split:"," %}{{ element if forloop.last }}{% endfor %}{% endmacro %} |
|
{% macro SugarArrayElement target %}{{ target|replace:"[",""|replace:"]","" }}{% endmacro %} |
|
{% macro ArrayElement target %}{{ target|replace:"Array",""|replace:"<",""|replace:">","" }}{% endmacro %} |
|
{% macro SetElement target %}{{ target|replace:"Set<",""|replace:">","" }}{% endmacro %} |
|
{% macro FormatClassName target %}{% set tmp1 %}{% call FormatOptional target %}{% endset %}{% set tmp2 %}{% call FormatGenerics tmp1 %}{% endset %}{% call FormatInnerType tmp2 %}{% endmacro %} |
|
{% macro FormatOptional target %}{{ target|replace:"?",""|replace:"!","" }}{% endmacro %} |
|
{% macro FormatGenerics target %}{{ target|replace:"<","~"|replace:">","~" }}{% endmacro %} |
|
{% macro FormatInnerType target %}{{ target|replace:".","__" }}{% endmacro %} |
|
{% macro PrefixFirst target separator %}{% for element in target|split:separator %}{{ element if forloop.first }}{% endfor %}{% endmacro %} |
|
|
|
{# --- macro definitions end --- #} |
|
|
|
```mermaid |
|
classDiagram |
|
{% for type in types.protocols %} |
|
|
|
class {% call FormatClassName type.name %} { |
|
<<interface>> |
|
{% call Variables type %} |
|
{% call Methods type %} |
|
} |
|
{% call ProtocolRelationships type %} |
|
|
|
{% endfor %} |
|
{% for type in types.classes %} |
|
|
|
class {% call FormatClassName type.name %} { |
|
{% call Variables type %} |
|
{% call Methods type %} |
|
} |
|
{% call ClassRelationships type %} |
|
|
|
{% endfor %} |
|
``` |