How to use the pyecore.ecore.EEnum function in pyecore

To help you get started, we’ve selected a few pyecore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyecore / pyecoregen / tests / test_ecore.py View on Github external
def test__ecore_task__filtered_elements():
    # prepare test model:
    # -------------------
    # ThePackage
    #   Class1
    #   SubPackage
    #     Class2
    #     MyEnum
    package = EPackage('ThePackage')
    class1 = EClass('Class1')
    class2 = EClass('Class2')
    enum = EEnum('MyEnum', literals=['A', 'B'])

    subpackage = EPackage('SubPackage')
    package.eSubpackages.append(subpackage)

    package.eClassifiers.append(class1)
    subpackage.eClassifiers.extend([class2, enum])

    task = EcoreTask()

    task.element_type = EPackage
    assert set(task.filtered_elements(package)) == {package, subpackage}

    task.element_type = EClass
    assert set(task.filtered_elements(package)) == {class1, class2}

    task.element_type = EEnum
github pyecore / pyecoregen / tests / test_ecore.py View on Github external
subpackage = EPackage('SubPackage')
    package.eSubpackages.append(subpackage)

    package.eClassifiers.append(class1)
    subpackage.eClassifiers.extend([class2, enum])

    task = EcoreTask()

    task.element_type = EPackage
    assert set(task.filtered_elements(package)) == {package, subpackage}

    task.element_type = EClass
    assert set(task.filtered_elements(package)) == {class1, class2}

    task.element_type = EEnum
    assert set(task.filtered_elements(package)) == {enum}
github pyecore / pyecoregen / tests / test_templates.py View on Github external
def test_package_with_enum(pygen_output_dir):
    enumpkg = EPackage('enumpkg')
    enum = EEnum('MyEnum', literals=('X', 'Y', 'Z'))
    enumpkg.eClassifiers.append(enum)

    mm = generate_meta_model(enumpkg, pygen_output_dir)

    generated_enum = mm.eClassifiers['MyEnum']
    assert isinstance(generated_enum, EEnum)
    assert set(l.name for l in generated_enum.eLiterals) == {'X', 'Y', 'Z'}
github pyecore / pyecore / tests / wikilibrary / wikilib.py View on Github external
https://fr.wikipedia.org/wiki/Eclipse_Modeling_Framework#/media/File:EMF_based_meta-model.png
The static metamodel had been produced by hand in this example
"""
import sys
import pyecore.ecore as Ecore
from pyecore.ecore import EObject, EAttribute, EString, EEnum, EReference, \
                          MetaEClass, EInteger

name = 'library'
nsPrefix = 'lib'
nsURI = 'http://emf.wikipedia.org/2011/Library'

# Do not remove
eClass = Ecore.EPackage(name=name, nsURI=nsURI, nsPrefix=nsPrefix)

BookCategory = EEnum('BookCategory', literals=['ScienceFiction',
                                               'Biography',
                                               'Mistery'])



class Book(EObject, metaclass=MetaEClass):
    title = EAttribute(eType=EString)
    pages = EAttribute(eType=EInteger)
    category = EAttribute(eType=BookCategory,
                          default_value=BookCategory.ScienceFiction)

    def __init__(self):
        super().__init__()


class Writer(EObject, metaclass=MetaEClass):
github pyecore / pyecoregen / tests / test_templates.py View on Github external
def test_user_module_default_values(pygen_output_dir):
    rootpkg = EPackage('with_default_values')
    e1 = EEnum('MyEnum', literals=('None_', 'A', 'B'))
    rootpkg.eClassifiers.append(e1)

    c1 = EClass('MyClass')
    a1 = EAttribute('a1', EString)
    a1.defaultValueLiteral = 'my_str'

    a2 = EAttribute('a2', EInt)
    a2.defaultValueLiteral = '7654321'

    a3 = EAttribute('a3', e1)
    a3.defaultValueLiteral = 'None'
    c1.eStructuralFeatures.extend([a1, a2, a3])
    rootpkg.eClassifiers.append(c1)

    mm = generate_meta_model(rootpkg, pygen_output_dir)
github pyecore / pyecoregen / tests / test_templates.py View on Github external
def test_classifier_imports(pygen_output_dir):
    # super types and enums from another package have to be imported in using module:
    rootpkg = EPackage('import_test')
    ppkg = EPackage('provider')
    upkg = EPackage('user')
    rootpkg.eSubpackages.extend([ppkg, upkg])

    super_class = EClass('SuperClass')
    enum = EEnum('AnEnum', literals=('A', 'B'))
    ppkg.eClassifiers.extend((super_class, enum))
    derived_class = EClass('DerivedClass', superclass=super_class)
    derived_class.eStructuralFeatures.append(EAttribute('kind', enum))
    upkg.eClassifiers.append(derived_class)

    # simply importing successully shows the imports have made the types visible
    mm = generate_meta_model(rootpkg, pygen_output_dir)
    assert mm
github pyecore / pyecore / pyecore / ecore.py View on Github external
upper=-1, derived=True)
EClass.eSuperTypes = EReference('eSuperTypes', EClass, upper=-1)
EClass.eOperations = EReference('eOperations', EOperation,
                                upper=-1, containment=True)
EClass.instanceClassName = EAttribute('instanceClassName', EString)
EClass.interface = EAttribute('interface', EBoolean)

EStructuralFeature.eContainingClass = \
                   EReference('eContainingClass', EClass,
                              eOpposite=EClass.eStructuralFeatures)

EReference.containment = EAttribute('containment', EBoolean)
EReference.eOpposite_ = EReference('eOpposite', EReference)
EReference.resolveProxies = EAttribute('resolveProxies', EBoolean)

EEnum.eLiterals = EReference('eLiterals', EEnumLiteral, upper=-1,
                             containment=True)

EEnumLiteral.eEnum = EReference('eEnum', EEnum, eOpposite=EEnum.eLiterals)
EEnumLiteral.name = EAttribute('name', EString)
EEnumLiteral.value = EAttribute('value', EInteger)
EEnumLiteral.literal = EAttribute('literal', EString)

EOperation.eContainingClass = EReference('eContainingClass', EClass,
                                         eOpposite=EClass.eOperations)
EOperation.eParameters = EReference('eParameters', EParameter, upper=-1,
                                    containment=True)
EOperation.eExceptions = EReference('eExceptions', EClassifier, upper=-1)
EOperation.eTypeParameters = EReference('eTypeParameters', ETypeParameter,
                                        upper=-1, containment=True)
EOperation.eGenericExceptions = EReference('eGenericExceptions', EGenericType,
                                           upper=-1)
github pyecore / pyecoregen / pyecoregen / ecore.py View on Github external
def manage_default_value(attribute: ecore.EAttribute):
        default_value = attribute.defaultValueLiteral
        if isinstance(attribute.eType, ecore.EEnum):
            default_value = fix_name_clash(default_value)
        default_value = attribute.eType.from_string(default_value)
        if isinstance(default_value, ecore.EEnumLiteral):
            default_value = '{e.eEnum.name}.{e.name}'.format(e=default_value)
        elif isinstance(default_value, ecore.EString):
            default_value = '{d!r}'.format(d=default_value)
        return default_value
github pyecore / pyecore / examples / wikilibrary / static / library.py View on Github external
https://fr.wikipedia.org/wiki/Eclipse_Modeling_Framework#/media/File:EMF_based_meta-model.png
The static metamodel had been produced by hand in this example
"""
import sys
import pyecore.ecore as Ecore
from pyecore.ecore import EObject, EAttribute, EString, EEnum, EReference, \
                          MetaEClass, EInteger

name = 'library'
nsPrefix = 'lib'
nsURI = 'http://emf.wikipedia.org/2011/Library'

# Do not remove
eClass = Ecore.EPackage(name=name, nsURI=nsURI, nsPrefix=nsPrefix)

BookCategory = EEnum('BookCategory', literals=['ScienceFiction',
                                               'Biography',
                                               'Mistery'])



class Book(EObject, metaclass=MetaEClass):
    title = EAttribute(eType=EString)
    pages = EAttribute(eType=EInteger)
    category = EAttribute(eType=BookCategory,
                          default_value=BookCategory.ScienceFiction)

    def __init__(self):
        pass


class Writer(EObject, metaclass=MetaEClass):