diff --git a/src/codegen.inc.php b/src/codegen.inc.php index 4282c8a..bf8631d 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -35,7 +35,10 @@ function supported_tokens() 'diffable', 'bhl_bind', 'cs_attributes', - 'cs_accessor_interface' + 'cs_accessor_interface', + 'cs_propget_interface', + 'cs_propset_interface', + 'cs_propgetset_interface', //TODO: //'i18n' ]; @@ -497,19 +500,16 @@ function get_diff_related_units(\mtgMetaStruct $struct) return $result; } -class AccessorInterface +class AccessorInterfaceField { public $field; - public $cs_interface_name; + public $is_propget; + public $is_propset; + public $is_accessor; function getUID() { - return $this->getInterfaceName(); - } - - function getInterfaceName() - { - return $this->cs_interface_name; + return $this->field->getName(); } function getCamelFieldName() @@ -522,16 +522,58 @@ class AccessorInterface } } +class AccessorInterface +{ + public $cs_interface_name; + public $fields = array(); + + function getUID() + { + return $this->getInterfaceName(); + } + + function getInterfaceName() + { + return $this->cs_interface_name; + } +} + function get_accessor_interfaces(\mtgMetaStruct $struct) { $ifs = array(); foreach($struct->getFields() as $field) { - if($field->hasToken('cs_accessor_interface')) + $is_accessor = $field->hasToken('cs_accessor_interface'); + $is_propget = $field->hasToken('cs_propget_interface'); + $is_propset = $field->hasToken('cs_propset_interface'); + $is_propgetset = $field->hasToken('cs_propgetset_interface'); + if($is_accessor || $is_propget || $is_propset || $is_propgetset) { $ai = new AccessorInterface(); - $ai->field = $field; - $ai->cs_interface_name = $field->getToken('cs_accessor_interface'); + + if($is_accessor) + $ai->cs_interface_name = $field->getToken('cs_accessor_interface'); + elseif($is_propget) + $ai->cs_interface_name = $field->getToken('cs_propget_interface'); + elseif($is_propset) + $ai->cs_interface_name = $field->getToken('cs_propset_interface'); + elseif($is_propgetset) + $ai->cs_interface_name = $field->getToken('cs_propgetset_interface'); + + if(array_key_exists($ai->getUID(), $ifs)) + $ai = $ifs[$ai->getUID()]; + + $aif = new AccessorInterfaceField(); + $aif->field = $field; + + if(array_key_exists($aif->getUID(), $ai->fields)) + $aif = $ai->fields[$aif->getUID()]; + + $aif->is_propget |= $is_propgetset || $is_propget; + $aif->is_propset |= $is_propgetset || $is_propset; + $aif->is_accessor |= $is_accessor; + + $ai->fields[$aif->getUID()] = $aif; $ifs[$ai->getUID()] = $ai; } } diff --git a/tpl/macro.twig b/tpl/macro.twig index 07f9d75..05774cb 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -618,21 +618,51 @@ public class {{o.name}} : IRpc {% macro decl_accessor_interface(ai) ~%} public interface {{ai.interfacename}} { - {{ai.field.type|cs_type}} Get{{ai.camelfieldname}}(); - void Set{{ai.camelfieldname}}({{ai.field.type|cs_type}} v); + {%- for aif in ai.fields ~%} + {% if aif.is_accessor -%} + {{aif.field.type|cs_type}} Get{{aif.camelfieldname}}(); + void Set{{aif.camelfieldname}}({{aif.field.type|cs_type}} v); + {% endif -%} + + {%- if aif.is_propget -%} + {{aif.field.type|cs_type}} {{aif.camelfieldname}} { + {%- if aif.is_propget -%} + get; + {%- endif %} + {%- if aif.is_propset -%} + set; + {%- endif -%} + } + {%- endif ~%} + {%- endfor ~%} } {% endmacro %} {%- macro decl_struct_accessor_implements(o) -%} {%- for ai in get_accessor_interfaces(o) ~%} -public {{ai.field.type|cs_type}} Get{{ai.camelfieldname}}() -{ - return {{ai.field.name}}; -} -public void Set{{ai.camelfieldname}}({{ai.field.type|cs_type}} v) -{ - this.{{ai.field.name}} = v; -} +{%- for aif in ai.fields ~%} +{% if aif.is_accessor %} + public {{aif.field.type|cs_type}} Get{{aif.camelfieldname}}() + { + return {{aif.field.name}}; + } + public void Set{{aif.camelfieldname}}({{aif.field.type|cs_type}} v) + { + this.{{aif.field.name}} = v; + } +{% endif %} + +{% if aif.is_propget or aif.is_propset %} + public {{aif.field.type|cs_type}} {{aif.camelfieldname}} { + {%- if aif.is_propget -%} + get => this.{{aif.field.name}}; + {%- endif -%} + {%- if aif.is_propset -%} + set => this.{{aif.field.name}} = value; + {%- endif -%} + } +{%- endif ~%} +{% endfor %} {%- endfor ~%} {% endmacro %}