Skip to content

Commit

Permalink
Merge pull request #109 from SokaDance/dynamic
Browse files Browse the repository at this point in the history
[ecore] remove dynamic properties management in DynamicEObjectImpl
  • Loading branch information
SokaDance authored Apr 27, 2023
2 parents d92c302 + 7fd906e commit 8d0a2b2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 45 deletions.
2 changes: 1 addition & 1 deletion ecore/abstractenotifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func newNotifierNotification(notifier *AbstractENotifier, eventType EventType, o
func newNotifierAdapterList(notifier *AbstractENotifier) *notifierAdapterList {
l := new(notifierAdapterList)
l.data = []any{}
l.isUnique = true
l.isUnique = false
l.interfaces = l
l.notifier = notifier
return l
Expand Down
6 changes: 0 additions & 6 deletions ecore/basiceobject_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ func (o *BasicEObjectImpl) ECrossReferences() EList {
return properties.crossReferences
}

func (o *BasicEObjectImpl) resetContentsLists() {
properties := o.getObjectProperties()
properties.contents = nil
properties.crossReferences = nil
}

// ESetContainer ...
func (o *BasicEObjectImpl) ESetInternalContainer(newContainer EObject, newContainerFeatureID int) {
o.container = newContainer
Expand Down
30 changes: 3 additions & 27 deletions ecore/dynamiceobject_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,9 @@ package ecore
type DynamicEObjectImpl struct {
EObjectImpl
class EClass
adapter *dynamicFeaturesAdapter
properties []any
}

type dynamicFeaturesAdapter struct {
AbstractEAdapter
object *DynamicEObjectImpl
}

func (adapter *dynamicFeaturesAdapter) NotifyChanged(notification ENotification) {
eventType := notification.GetEventType()
if eventType != REMOVING_ADAPTER {
featureID := notification.GetFeatureID()
if featureID == ECLASS__ESTRUCTURAL_FEATURES {
adapter.object.resizeProperties()
adapter.object.resetContentsLists()
}
}
}

// NewDynamicEObjectImpl is the constructor of a DynamicEObjectImpl
func NewDynamicEObjectImpl() *DynamicEObjectImpl {
o := new(DynamicEObjectImpl)
Expand All @@ -43,7 +26,6 @@ func NewDynamicEObjectImpl() *DynamicEObjectImpl {

func (o *DynamicEObjectImpl) Initialize() {
o.EObjectImpl.Initialize()
o.adapter = &dynamicFeaturesAdapter{object: o}
o.resizeProperties()
}

Expand All @@ -57,15 +39,9 @@ func (o *DynamicEObjectImpl) EClass() EClass {

// SetEClass ...
func (o *DynamicEObjectImpl) SetEClass(class EClass) {
if o.class != nil {
o.class.EAdapters().Remove(o.adapter)
}

o.class = class
o.resizeProperties()

if o.class != nil {
o.class.EAdapters().Add(o.adapter)
if class != o.class {
o.class = class
o.resizeProperties()
}
}

Expand Down
18 changes: 7 additions & 11 deletions ecore/dynamiceobject_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestDynamicEObjectConstructor(t *testing.T) {
Expand All @@ -25,10 +24,7 @@ func TestDynamicEObjectConstructor(t *testing.T) {
func TestDynamicEObject_EClass(t *testing.T) {
o := NewDynamicEObjectImpl()
mockClass := NewMockEClass(t)
mockAdapters := NewMockEList(t)
mockClass.EXPECT().GetFeatureCount().Return(0)
mockClass.EXPECT().EAdapters().Return(mockAdapters)
mockAdapters.EXPECT().Add(mock.Anything).Return(true).Once()
mockClass.EXPECT().GetFeatureCount().Return(0).Once()
o.SetEClass(mockClass)
assert.Equal(t, mockClass, o.EClass())
}
Expand All @@ -47,11 +43,11 @@ func TestDynamicEObject_MockEClass(t *testing.T) {
func TestDynamicEObject_GetSet(t *testing.T) {
o := NewDynamicEObjectImpl()
c := GetFactory().CreateEClass()
o.SetEClass(c)
assert.Equal(t, c, o.EClass())

f := GetFactory().CreateEAttribute()
c.GetEStructuralFeatures().Add(f)

o.SetEClass(c)
assert.Equal(t, c, o.EClass())
assert.Nil(t, o.EGet(f))

o.ESet(f, 1)
Expand All @@ -61,11 +57,11 @@ func TestDynamicEObject_GetSet(t *testing.T) {
func TestDynamicEObject_Unset(t *testing.T) {
o := NewDynamicEObjectImpl()
c := GetFactory().CreateEClass()
o.SetEClass(c)
assert.Equal(t, c, o.EClass())

f := GetFactory().CreateEAttribute()
c.GetEStructuralFeatures().Add(f)

o.SetEClass(c)
assert.Equal(t, c, o.EClass())
assert.Nil(t, o.EGet(f))

o.ESet(f, 1)
Expand Down

0 comments on commit 8d0a2b2

Please sign in to comment.