Skip to content

Commit 4441b1e

Browse files
committed
Merge branch 'master' of github.com:pyecore/pyecoregen
2 parents 0595405 + 799dfe6 commit 4441b1e

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

pyecoregen/ecore.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,14 @@ class EcoreGenerator(multigen.jinja.JinjaGenerator):
109109

110110
@staticmethod
111111
def test_type(value, type_):
112-
"""Jinja test to check object type."""
112+
"""Jinja test to check if an object's class is exactly the tested type."""
113+
return value.__class__ is type_
114+
115+
@staticmethod
116+
def test_kind(value, type_):
117+
"""Jinja test to check the 'kind' or an object.
118+
An object is 'kind' of a type when the object's class isinstance from the tested type.
119+
"""
113120
return isinstance(value, type_)
114121

115122
@staticmethod
@@ -208,6 +215,7 @@ def create_environment(self, **kwargs):
208215
environment = super().create_environment(**kwargs)
209216
environment.tests.update({
210217
'type': self.test_type,
218+
'kind': self.test_kind,
211219
'opposite_before_self': self.test_opposite_before_self,
212220
})
213221
environment.filters.update({

pyecoregen/templates/module.py.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ class {{ c.name }}({{ c | supertypes }}):
136136

137137
{#- -------------------------------------------------------------------------------------------- -#}
138138

139-
{%- for c in element.eClassifiers if c is type(ecore.EEnum) %}
139+
{%- for c in element.eClassifiers if c is type(ecore.EEnum) -%}
140140
{{ generate_enum(c) }}
141141
{%- endfor %}
142-
{%- for c in element.eClassifiers if c is type(ecore.EDataType) and c is not type(ecore.EEnum)%}
142+
{% for c in element.eClassifiers if c is type(ecore.EDataType) -%}
143143
{{ generate_edatatype(c) }}
144144
{%- endfor %}
145145

pyecoregen/templates/package.py.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ eSuperPackage = {{ element.eSuperPackage.name | default('None') }}
4646
{%- endwith %}
4747
{%- endif %}
4848

49-
otherClassifiers = [{{ element.eClassifiers | select('type', ecore.EDataType) | map(attribute='name') | join(', ') }}]
49+
otherClassifiers = [{{ element.eClassifiers | select('kind', ecore.EDataType) | map(attribute='name') | join(', ') }}]
5050

5151
for classif in otherClassifiers:
5252
eClassifiers[classif.name] = classif

0 commit comments

Comments
 (0)