Adding initial support for @cs_accessor_interface
This commit is contained in:
parent
a12644063f
commit
a0a96b0a45
|
@ -135,6 +135,18 @@ function _add_twig_support(\Twig\Environment $twig)
|
|||
return get_diff_related_units($o);
|
||||
}
|
||||
));
|
||||
$twig->addFunction(new \Twig\TwigFunction('get_all_accessor_interfaces',
|
||||
function($o)
|
||||
{
|
||||
return get_all_accessor_interfaces($o);
|
||||
}
|
||||
));
|
||||
$twig->addFunction(new \Twig\TwigFunction('get_accessor_interfaces',
|
||||
function($o)
|
||||
{
|
||||
return get_accessor_interfaces($o);
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
function cs_type(\mtgType $type)
|
||||
|
@ -483,3 +495,61 @@ function get_diff_related_units(\mtgMetaStruct $struct)
|
|||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
class AccessorInterface
|
||||
{
|
||||
public $field;
|
||||
public $cs_interface_name;
|
||||
|
||||
function getUID()
|
||||
{
|
||||
return $this->getInterfaceName();
|
||||
}
|
||||
|
||||
function getInterfaceName()
|
||||
{
|
||||
return $this->cs_interface_name;
|
||||
}
|
||||
|
||||
function getCamelFieldName()
|
||||
{
|
||||
$name_parts = explode("_", $this->field->getName());
|
||||
$uc_parts = array();
|
||||
foreach($name_parts as $part)
|
||||
$uc_parts[] = ucfirst($part);
|
||||
return implode($uc_parts);
|
||||
}
|
||||
}
|
||||
|
||||
function get_accessor_interfaces(\mtgMetaStruct $struct)
|
||||
{
|
||||
$ifs = array();
|
||||
foreach($struct->getFields() as $field)
|
||||
{
|
||||
if($field->hasToken('cs_accessor_interface'))
|
||||
{
|
||||
$ai = new AccessorInterface();
|
||||
$ai->field = $field;
|
||||
$ai->cs_interface_name = $field->getToken('cs_accessor_interface');
|
||||
$ifs[$ai->getUID()] = $ai;
|
||||
}
|
||||
}
|
||||
return $ifs;
|
||||
}
|
||||
|
||||
function get_all_accessor_interfaces(\mtgMetaInfo $info)
|
||||
{
|
||||
$all = array();
|
||||
foreach($info->getUnits() as $unit)
|
||||
{
|
||||
if($unit->object instanceof \mtgMetaStruct)
|
||||
$all = array_merge($all, get_accessor_interfaces($unit->object));
|
||||
else if($unit->object instanceof \mtgMetaRPC)
|
||||
{
|
||||
$all = array_merge($all, get_accessor_interfaces($unit->object->getReq()));
|
||||
$all = array_merge($all, get_accessor_interfaces($unit->object->getRsp()));
|
||||
}
|
||||
}
|
||||
return $all;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
{%- endif ~%}
|
||||
{%- endfor ~%}
|
||||
|
||||
{%- for ai in get_all_accessor_interfaces(meta) ~%}
|
||||
{{ _self.decl_accessor_interface(ai) }}
|
||||
{%- endfor ~%}
|
||||
|
||||
{% endmacro %}
|
||||
|
||||
{% macro decl_struct(o, extra = '') %}
|
||||
|
@ -110,6 +114,8 @@ public {{_self.struct_type(o)}} {{o.name}} {{_self.base_struct_class(o)}}
|
|||
{{_self.diffable_support(o)}}
|
||||
{%- endif -%}
|
||||
|
||||
{{_self.decl_struct_accessor_implements(o)}}
|
||||
|
||||
{{extra}}
|
||||
}
|
||||
|
||||
|
@ -169,6 +175,9 @@ ResetFieldMask();
|
|||
{{- has_token(o, 'cloneable') and not o.parent ? ', IMetaCloneable' -}}
|
||||
{{- has_token(o, 'bhl_bind') and not o.parent ? ', bhl.ITyped' -}}
|
||||
{%- endif -%}
|
||||
{%- for ai in get_accessor_interfaces(o) -%}
|
||||
, {{ai.interfacename}}
|
||||
{%- endfor -%}
|
||||
{%- endmacro -%}
|
||||
|
||||
{%- macro override(o) -%}
|
||||
|
@ -605,3 +614,25 @@ public class {{o.name}} : IRpc
|
|||
{% endif %}
|
||||
|
||||
{% endmacro %}
|
||||
|
||||
{% 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);
|
||||
}
|
||||
{% 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;
|
||||
}
|
||||
{%- endfor ~%}
|
||||
{% endmacro %}
|
||||
|
||||
|
|
Loading…
Reference in New Issue