-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestMetamodelGenerator.xtend
174 lines (143 loc) · 5.61 KB
/
TestMetamodelGenerator.xtend
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package metamodel.generator
import java.nio.file.Paths
import java.nio.file.Files
class Main {
static val outputDir = Paths.get("/home/vitali/Public/Projects/AndroidStudioProj/Neo4jEMF/EmfModel/metamodel_test")
//static val outputDir = Paths.get("./model")
def static void main(String[] args) {
if(!Files.exists(metamodel.generator.Main.outputDir)) Files.createDirectories(metamodel.generator.Main.outputDir)
Files.walk(outputDir).map[it.toFile].filter[it.file].forEach[it.delete]
val testList = #[3, 2, 4]
val longList = #[20, 50, 70, 100, 120, 150, 170, 200, 250, 300, 370, 450, 540]
val shortList = #[1, 2, 3, 4, 5]
print("long list: ")
longList.forEach[ n |
genAttrString(n)
genSelfRef(n)
genRef(1, n, 1)
genRef(n, 1, 1)
longList.forEach[ q |
genRef(1, q, n)
genRef(n, q, 1)
]
//genSimpleInheritance(3, n)
//genSimpleInheritance(4, n)
//genSimpleInheritance(4, n)
print(n + " ")
]
println("\nFinished")
}
static def genAttrString(int n) {
val name = '''Attr_str_n«String.format("%03d", n)»'''
val writer = Files.newBufferedWriter(Paths.get('''«metamodel.generator.Main.outputDir»/«name».ecore'''))
writer.append('''
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
name="«name»" nsURI="«name»" nsPrefix="«name»">
<eClassifiers xsi:type="ecore:EClass" name="Root">
''')
for (i : 1..n) writer.append('''
<eStructuralFeatures xsi:type="ecore:EAttribute" name="a«i
»" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
''')
writer.append('''</eClassifiers></ecore:EPackage>''')
writer.close
}
static def genSelfRef(int n) {
val name = '''selfRef_«String.format("%03d", n)»'''
val writer = Files.newBufferedWriter(Paths.get('''«metamodel.generator.Main.outputDir»/«name».ecore'''))
writer.append('''
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
name="«name»" nsURI="«name»" nsPrefix="«name»">
<eClassifiers xsi:type="ecore:EClass" name="Src">
''')
for (i : 1..n) writer.append('''
<eStructuralFeatures xsi:type="ecore:EReference" name="ref_«i
»" containment="true" upperBound="-1" eType="#//Src" />
''')
writer.append('''</eClassifiers></ecore:EPackage>''')
writer.close
}
/**
* src : number of source nodes
* n : number refs between each src and target node
* targ: number of target nodes
*/
static def genRef(int src, int n, int tar) {
val name = '''Ref_src«String.format("%03d", src)»_n«String.format("%03d", n)»_tar«String.format("%03d", tar)»'''
val writer = Files.newBufferedWriter(Paths.get('''«metamodel.generator.Main.outputDir»/«name».ecore'''))
writer.append('''
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
name="«name»" nsURI="«name»" nsPrefix="«name»">
''')
for (i : 1..src) {
writer.append('''<eClassifiers xsi:type="ecore:EClass" name="Src_«i»">''' + "\n")
for (j : 1..tar) {
for (k : 1..n) {
writer.append('''
<eStructuralFeatures xsi:type="ecore:EReference" name="ref«k»To«j
»" containment="true" upperBound="-1" eType="#//Target_«j»"/>
''')
}
}
writer.append("</eClassifiers>\n")
}
for (i : 1..tar) {
writer.append('''<eClassifiers xsi:type="ecore:EClass" name="Target_«i»"/>''' + "\n")
}
writer.append('''</ecore:EPackage>''')
writer.close
}
/*
* @param depth is a depth of chain of inheritance
* @param width is a number of inherited elements for each element
*/
static def genSimpleInheritance(int depth, int width) {
val name = '''SimpleInheritance_depth«String.format("%03d", depth)»_width«String.format("%03d", width)»'''
val writer = Files.newBufferedWriter(Paths.get('''«metamodel.generator.Main.outputDir»/«name».ecore'''))
writer.append('''
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
name="«name»" nsURI="«name»" nsPrefix="«name»">
<eClassifiers xsi:type="ecore:EClass" name="Class_0_1_1" />
''')
for (i : 1..depth) {
var g = 1
var p = 1
for (j : 1..(new Double(Math.pow(width, i-1)).intValue())) { //groups
for (k : 1..width) {
writer.append('''
<eClassifiers xsi:type="ecore:EClass" name="Class_«i»_«j»_«k»" eSuperTypes="#//Class_«i-1»_«g»_«p»" />
''')
}
p++
if (j % width == 0) {g++ p=1}
}
}
writer.append('''</ecore:EPackage>''')
writer.close
}
static def genComplexModel(int attr, int ref, int depth, int width) {
val name = '''ComplexModel_attr«attr»_depth«depth»_width«width»'''
val writer = Files.newBufferedWriter(Paths.get('''«metamodel.generator.Main.outputDir»/«name».ecore'''))
writer.append('''
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
name="«name»" nsURI="«name»" nsPrefix="«name»">
''')
writer.append("")
writer.close
}
}