| /* |
| package de.hub.rcore.example |
| |
| import org.eclipse.emf.ecore.EDataType |
| import org.eclipse.emf.ecore.EcorePackage |
| import static de.hub.randomemf.runtime.Random.* |
| |
| generator RandomEcore for ecore |
| in "platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore" { |
| |
| Package: EPackage -> |
| name := LatinCamel(Normal(4,2)).toLowerCase |
| nsPrefix := RandomID(Normal(2.5,1)) |
| nsURI := "http://hub.de/rcore/examples/" + self.name |
| eClassifiers += Class#NegBinomial(5,0.5) |
| ; |
| |
| Class: EClass -> |
| name := LatinCamel(Normal(10,3)) |
| abstract := UniformBool(0.2) |
| eStructuralFeatures += Feature#NegBinomial(2,0.5) |
| ; |
| |
| alter Feature: EStructuralFeature -> |
| Reference(true) | Reference(false) | Attribute#2 |
| ; |
| |
| Reference(boolean composite):EReference -> |
| name := LatinCamel(Normal(10,3)).toFirstLower |
| upperBound := if (UniformBool(0.5)) -1 else 1 |
| ordered := UniformBool(0.2) |
| containment := composite |
| eType:EClass := Uniform(model.EClassifiers.filter[ |
| it instanceof org.eclipse.emf.ecore.EClass |
| ]) |
| ; |
| |
| Attribute:EAttribute -> |
| name := LatinCamel(Normal(8,3)).toFirstLower |
| upperBound := if (UniformBool(0.1)) -1 else 1 |
| eType:EDataType := Uniform(EcorePackage.eINSTANCE.EClassifiers.filter[ |
| it instanceof EDataType |
| ]) |
| ; |
| } |
| */ |
| operation EPackage create(){ |
| self.name= randomString(5,10); |
| |
| } |
| $instances 5 |
| operation EClass create(){ |
| self.name= randomString(7,13); |
| self.abstract= randomBoolean(0.2); |
| } |
| $instances 2 |
| operation EDataType create(){ |
| self.name= randomString(7,13); |
| } |
| operation createRef(composite:Boolean){ |
| var ref:EReference= new EReference; |
| ref.name= randomString(7,13); |
| ref.eType=EClass.all.randomD(); |
| if(randomBoolean(0.5)){ |
| ref.upperbound=-1; |
| } |
| else{ |
| ref.upperbound=1; |
| } |
| ref.containment=composite; |
| return ref; |
| } |
| |
| operation createAtr(){ |
| var atr:EAttribute= new EAttribute; |
| atr.name= randomString(7,13); |
| //atr.eType=EDataType.eINSTANCE; |
| //model.println(); |
| //atr.eType=EClass.all.randomD(); |
| if(randomBoolean(0.1)){ |
| atr.upperbound=-1; |
| } |
| else{ |
| atr.upperbound=1; |
| } |
| return atr; |
| } |
| pattern Package |
| pack:EPackage |
| from: EPackage.all, |
| clas:EClassifier |
| from: EClass.all |
| guard:true{ |
| onmatch{ |
| pack.eclassifiers.add(clas); |
| } |
| } |
| @probability 0.6 |
| pattern StructuralFeature |
| clas:EClass |
| from: EClass.all |
| guard:true{ |
| onmatch{ |
| for(j in Sequence{1..randomInteger(1,5)}){ |
| var i:Integer = randomInteger(10); |
| if(i<3){ |
| clas.eStructuralFeatures.add(createRef(true)); |
| } |
| else if(i<5){ |
| clas.eStructuralFeatures.add(createRef(false)); |
| } |
| else{ |
| clas.eStructuralFeatures.add(createAtr()); |
| } |
| } |
| } |
| } |