How to use the pyecore.ecore.EAttribute 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_templates.py View on Github external
def test_user_module_derived_from_mixin_(pygen_output_dir):
    rootpkg = EPackage('derived_from_mixin')
    c1 = EClass('MyClass')
    c1.eOperations.append(EOperation('do_it'))
    c1.eStructuralFeatures.append(EAttribute('any', EString, derived=True))
    rootpkg.eClassifiers.append(c1)
    c2 = EClass('MyOtherClass')
    c2.eStructuralFeatures.append(EAttribute('other', EString, derived=True))
    c2.eStructuralFeatures.append(EReference('toc', c1, derived=True))
    c2.eSuperTypes.append(c1)
    rootpkg.eClassifiers.append(c2)

    mm = generate_meta_model(rootpkg, pygen_output_dir, user_module='user_provided.module')

    c = mm.MyOtherClass(any='any', other='other')
    assert isinstance(c, MyClassMixin)
    assert isinstance(c, MyOtherClassMixin)
    assert isinstance(c, mm.MyClass)
    assert c.any == 'any'
    c.mock_other.assert_called_once_with('other')

    assert not c.do_it.called
    c.do_it()
    assert c.do_it.called
github pyecore / pyecore / tests / wikilibrary / wikilib.py View on Github external
super().__init__()


class Writer(EObject, metaclass=MetaEClass):
    name = EAttribute(eType=EString)
    books = EReference(eType=Book, lower=1, upper=-1)


Book.authors = EReference('authors', Writer, lower=1, upper=-1,
                          eOpposite=Writer.books)
Book.eClass.eStructuralFeatures.append(Book.authors)


class Employee(EObject, metaclass=MetaEClass):
    name = EAttribute(eType=EString)
    age = EAttribute(eType=EInteger)


class Library(EObject, metaclass=MetaEClass):
    name = EAttribute(eType=EString)
    address = EAttribute(eType=EString)
    employees = EReference(eType=Employee, upper=-1, containment=True)
    writers = EReference(eType=Writer, upper=-1, containment=True)
    books = EReference(eType=Book, upper=-1, containment=True)


# ==
#   Warning, do not remove
# ==
eURIFragment = Ecore.default_eURIFragment
eModule = sys.modules[__name__]
otherClassifiers = [BookCategory]
github pyecore / pyecore / tests / json / test_json_save.py View on Github external
child = Ecore.EReference(containment=True, upper=-1)
    imply = Ecore.EReference()
    ref_by = Ecore.EReference()
    distant = Ecore.EReference(eType=Ecore.EObject)


A.child.eType = A
A.imply.eType = A
A.ref_by.eType = A


@Ecore.EMetaclass
class Point(object):
    x = Ecore.EAttribute(eType=Ecore.EDouble)
    y = Ecore.EAttribute(eType=Ecore.EDouble)
    z = Ecore.EAttribute(eType=Ecore.EDouble)


def test_json_resource_save_static_metamodel(tmpdir):
    f = tmpdir.mkdir('pyecore-tmp').join('test.json')
    resource = JsonResource(URI(str(f)))

    # we add the elements to the resource
    resource.append(eClass)
    resource.save()

    # we read the model
    resource = JsonResource(URI(str(f)))
    resource.load()
    assert resource.contents != []
    assert len(resource.contents[0].eContents) == 2
github pyecore / pyecoregen / tests / test_generated_library.py View on Github external
def test_meta_attribute_access(generated_library):
    assert isinstance(generated_library.Book.category, Ecore.EAttribute)
    attribute = generated_library.Book.category
    assert attribute.name == 'category'
    assert attribute.upperBound == 1
    assert attribute.lowerBound == 0
    assert isinstance(attribute.eType, Ecore.EDataType)
    assert attribute.eType is generated_library.BookCategory
github pyecore / pyecore / pyecore / ecore.py View on Github external
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)

EParameter.eOperation = EReference('eOperation', EOperation,
                                   eOpposite=EOperation.eParameters)

ETypeParameter.eBounds = EReference('eBounds', EGenericType,
                                    upper=-1, containment=True)
github pyecore / pyecore / examples / wikilibrary / static / library.py View on Github external
class Writer(EObject, metaclass=MetaEClass):
    name = EAttribute(eType=EString)
    books = EReference(eType=Book, lower=1, upper=-1)

    def __init__(self):
        pass


Book.authors = EReference('authors', Writer, lower=1, upper=-1,
                          eOpposite=Writer.books)
Book.eClass.eStructuralFeatures.append(Book.authors)


class Employee(EObject, metaclass=MetaEClass):
    name = EAttribute(eType=EString)
    age = EAttribute(eType=EInteger)

    def __init__(self):
        pass


class Library(EObject, metaclass=MetaEClass):
    name = EAttribute(eType=EString)
    address = EAttribute(eType=EString)
    employees = EReference(eType=Employee, upper=-1, containment=True)
    writers = EReference(eType=Writer, upper=-1, containment=True)
    books = EReference(eType=Book, upper=-1, containment=True)

    def __init__(self):
        pass
github pyecore / pyecore / examples / wikilibrary / static / library.py View on Github external
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):
    name = EAttribute(eType=EString)
    books = EReference(eType=Book, lower=1, upper=-1)

    def __init__(self):
        pass


Book.authors = EReference('authors', Writer, lower=1, upper=-1,
github pyecore / pyecore / pyecore / ecore.py View on Github external
ETypedElement.ordered = EAttribute('ordered', EBoolean, default_value=True)
ETypedElement.unique = EAttribute('unique', EBoolean, default_value=True)
ETypedElement._lower = EAttribute('lower', EInteger, derived=True)
ETypedElement.lowerBound = EAttribute('lowerBound', EInteger)
ETypedElement._upper = EAttribute('upper', EInteger, derived=True)
ETypedElement.upperBound = EAttribute('upperBound', EInteger, default_value=1)
ETypedElement.required = EAttribute('required', EBoolean)
ETypedElement.eGenericType = EReference('eGenericType', EGenericType,
                                        containment=True)
ETypedElement.eType = EReference('eType', EClassifier)
ENamedElement.name._isset.add(ETypedElement.eType)  # special case

EStructuralFeature.changeable = EAttribute('changeable', EBoolean,
                                           default_value=True)
EStructuralFeature.volatile = EAttribute('volatile', EBoolean)
EStructuralFeature.transient = EAttribute('transient', EBoolean)
EStructuralFeature.unsettable = EAttribute('unsettable', EBoolean)
EStructuralFeature.derived = EAttribute('derived', EBoolean)
EStructuralFeature.defaultValueLiteral = EAttribute('defaultValueLiteral',
                                                    EString)

EAttribute.iD = EAttribute('iD', EBoolean)

EPackage.nsURI = EAttribute('nsURI', EString)
EPackage.nsPrefix = EAttribute('nsPrefix', EString)
EPackage.eClassifiers = EReference('eClassifiers', EClassifier,
                                   upper=-1, containment=True)
EPackage.eSubpackages = EReference('eSubpackages', EPackage,
                                   upper=-1, containment=True)
EPackage.eSuperPackage = EReference('eSuperPackage', EPackage,
                                    lower=1, eOpposite=EPackage.eSubpackages)