| modeltype ECORE uses "http://www.eclipse.org/emf/2002/Ecore"; |
| |
| |
| transformation moduleProperty(in inMode:ECORE, out outModel : ECORE); |
| |
| property nestedColProp : Sequence(Set(Tuple(firstName : String, surname : String))) = null; |
| |
| property propInt : Integer = 10; |
| property propReal : Real = 10.0; |
| property propBool : Boolean = true; |
| |
| property propStr : String = ''; |
| property propStrOrderedSet : OrderedSet(String) = OrderedSet {}; |
| property propStrSet : Set(String) = Set {}; |
| property propStrBag : Bag(String) = Bag {}; |
| property propStrSeq : Sequence(String) = Sequence {}; |
| |
| property tupleProp : Sequence(Set(Tuple(firstName : String, surname : String))) = Sequence{Set{Tuple{firstName = '', surname = ''}}}; |
| |
| property ePropStrOrderedSet : OrderedSet(EClassifier) = OrderedSet {}; |
| property ePropStrSet : Set(EClassifier) = Set {}; |
| property ePropStrBag : Bag(EClassifier) = Bag {}; |
| property ePropStrSeq : Sequence(EClassifier) = Sequence {}; |
| |
| |
| main() { |
| var p := object EPackage { |
| name := 'results'; |
| }; |
| |
| map testStdTypes(p); |
| |
| var localOrderedSet : OrderedSet(String) := OrderedSet { 'a', 'b' }; |
| this.propStrOrderedSet += localOrderedSet; |
| this.propStrOrderedSet += invalid; |
| |
| assert fatal (localOrderedSet->includesAll(this.propStrOrderedSet)); |
| p.eClassifiers += map foo('propStrOrderedSet', propStrOrderedSet); |
| |
| this.propStrSet += localOrderedSet; |
| assert fatal (localOrderedSet->includesAll(this.propStrSet)); |
| p.eClassifiers += map foo('propStrSet', propStrSet); |
| |
| this.propStrBag += localOrderedSet; |
| assert fatal (localOrderedSet->includesAll(this.propStrBag)); |
| p.eClassifiers += map foo('propStrBag', propStrBag); |
| |
| this.propStrSeq += localOrderedSet; |
| assert fatal (localOrderedSet->includesAll(this.propStrSeq)); |
| p.eClassifiers += map foo('propStrSeq', propStrSeq); |
| |
| this.nestedColProp := Sequence { Set { Tuple { firstName = 'John', surname = 'Smith' } } }; |
| p.eClassifiers += map foo('nestedColProp', nestedColProp->collect(i | i)->collectNested(firstName + ' ' + surname)); |
| |
| p.eClassifiers += map foo('tupleProp', tupleProp->collect(i | i)->collectNested(firstName + '_' + surname)); |
| |
| this.ePropStrOrderedSet += object EClass { name := 'ePropStrOrderedSet' }; |
| this.ePropStrSet += object EClass { name := 'ePropStrSet' }; |
| this.ePropStrBag += object EClass { name := 'ePropStrBag' }; |
| this.ePropStrSeq += object EClass { name := 'ePropStrSeq' }; |
| |
| p.eClassifiers += ePropStrOrderedSet; |
| p.eClassifiers += ePropStrSet; |
| p.eClassifiers += ePropStrBag; |
| p.eClassifiers += ePropStrSeq; |
| |
| this.ePropStrOrderedSet := null; |
| assert fatal (this.ePropStrOrderedSet <> null); |
| |
| -- check that a copy of the let side property is used |
| this.ePropStrSet := ePropStrOrderedSet; |
| this.ePropStrSet += ePropStrSeq; |
| assert fatal (ePropStrSet->size() = ePropStrOrderedSet->size() + 1); |
| assert fatal (not ePropStrOrderedSet->includesAll(ePropStrSeq)); |
| } |
| |
| mapping foo(in pName : String, in values : Collection(String)) : EClass { |
| name := pName; |
| eStructuralFeatures += values->collect(s | object EAttribute { name := s }); |
| } |
| |
| mapping testStdTypes(in p : EPackage) { |
| init { |
| this.propStr := propStr + 'myString'; |
| assert fatal (propStr = 'myString'); |
| this.propStr := null; |
| assert fatal (propStr = null); |
| |
| this.propInt := propInt + 11; |
| assert fatal (propInt = 21); |
| this.propInt := null; |
| assert fatal (propInt = null); |
| |
| this.propReal := propReal + 15.5; |
| assert fatal (propReal = 25.5); |
| this.propReal := null; |
| assert fatal (propReal = null); |
| -- check Integer conforms to Real |
| this.propReal := propInt; |
| assert fatal (propReal = null); |
| } |
| } |