Skip to content

Commit 79bfa87

Browse files
authored
Code generator files
CSTL files for Java8 and Swift5, together with OCL libraries. Place the CSTL files in a subdirectory /cg of your installation directory (where umlrsds.jar is located). The Build menu option "Use CSTL file" uses cg/cg.cstl to translate a UML model to the target language. The output is written to /output/cgout.txt
1 parent 51d491c commit 79bfa87

File tree

2 files changed

+355
-8
lines changed

2 files changed

+355
-8
lines changed

cgJava.cstl

Lines changed: 344 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,344 @@
1+
--
2+
-- Main code-generation specification file for Java
3+
-- Version 8+. Also uses cginterface.cstl
4+
-- Depends on Ocl.java
5+
--
6+
-- Copyright (c) 2003,2020 Kevin Lano
7+
-- This program and the accompanying materials are
8+
-- made available under the
9+
-- terms of the Eclipse Public License 2.0
10+
-- which is available at
11+
-- http://www.eclipse.org/legal/epl-2.0
12+
--
13+
-- SPDX-License-Identifier: EPL-2.0
14+
--
15+
16+
17+
Package::
18+
package _1 { types: _2 classes: _3 usecases: _4 } |-->package _1;\n\nimport java.util.*;\nimport java.util.Map;\nimport java.util.HashMap;\n\n\n_2 \n_3\npublic class _1\n{ public static void main(String[] args) { }\n\n_4 \n}\n
19+
20+
21+
22+
Type::
23+
Sequence(String) |-->ArrayList<String>
24+
Sequence(int) |-->ArrayList<Integer>
25+
Sequence(double) |-->ArrayList<Double>
26+
Sequence(long) |-->ArrayList<Long>
27+
Sequence(boolean) |-->ArrayList<Boolean>
28+
29+
Set(String) |-->HashSet<String>
30+
Set(int) |-->HashSet<Integer>
31+
Set(double) |-->HashSet<Double>
32+
Set(long) |-->HashSet<Long>
33+
Set(boolean) |-->HashSet<Boolean>
34+
35+
Sequence(_1) |-->ArrayList<_1>
36+
Set(_1) |-->HashSet<_1>
37+
Map(_1,_2) |-->HashMap<_1,_2>
38+
39+
40+
41+
Enumeration::
42+
enumeration _1 { _2 } |-->enum _1 { _2 } \n
43+
44+
literal _1, _2 |-->_1, _2
45+
literal _1 |-->_1
46+
47+
48+
49+
50+
BasicExpression::
51+
self |-->this
52+
53+
_1 |-->_1`typename._1<when> _1 enumerationLiteral
54+
55+
_1.allInstances |-->_1._1_allInstances
56+
57+
_1.insertAt(_2,_3) |-->Ocl.insertAt(_1,_2,_3)
58+
59+
Integer.subrange(_1,_2) |-->Ocl.integerSubrange(_1,_2)
60+
61+
Integer.Sum(_1,_2,_3,_4) |-->Ocl.sum(Ocl.collectSequence(Ocl.integerSubrange(_1,_2),(_3)->{ return _4; }))
62+
63+
Integer.Prd(_1,_2,_3,_4) |-->Ocl.prd(Ocl.collectSequence(Ocl.integerSubrange(_1,_2),(_3)->{ return _4; }))
64+
65+
_1.subrange(_2,_3) |-->Ocl.subrange(_1,_2,_3)
66+
67+
_1[_2] |-->(_1.charAt(_2) + "")<when> _1 String
68+
_1[_2] |-->_1._1_index.get(_2)<when> _1 classId
69+
70+
_1[_2] |-->((_1`elementType) (_1).get(_2 - 1))<when> _2 numeric
71+
72+
_1[_2] |-->((_1`elementType) (_1).get(_2))<when> _2 not numeric
73+
74+
displayString(_1) |-->System.out.println(_1)
75+
displayint(_1) |-->System.out.println("" + _1)
76+
displaylong(_1) |-->System.out.println("" + _1)
77+
displayboolean(_1) |-->System.out.println("" + _1)
78+
79+
createByPK_1(_2) |-->_1.createByPK_1(_2)
80+
create_1() |-->_1.create_1()
81+
82+
_1._2(_3) |-->_1._2(_3)
83+
84+
_1._2 |-->_1._2
85+
86+
87+
88+
89+
90+
UnaryExpression::
91+
-_1 |-->-_1
92+
+_1 |-->+_1
93+
_1->log() |-->Math.log(_1)
94+
_1->exp() |-->Math.exp(_1)
95+
_1->sin() |-->Math.sin(_1)
96+
_1->cos() |-->Math.cos(_1)
97+
_1->tan() |-->Math.tan(_1)
98+
_1->asin() |-->Math.asin(_1)
99+
_1->acos() |-->Math.acos(_1)
100+
_1->atan() |-->Math.atan(_1)
101+
_1->sqr() |-->(_1)*(_1)
102+
_1->sqrt() |-->Math.sqrt(_1)
103+
_1->cbrt() |-->Math.cbrt(_1)
104+
_1->floor() |-->((int) Math.floor(_1))
105+
_1->ceil() |-->((int) Math.ceil(_1))
106+
_1->round() |-->((int) Math.round(_1))
107+
_1->abs() |-->Math.abs(_1)
108+
109+
_1->size() |-->_1.length()<when> _1 String
110+
_1->size() |-->_1.size()<when> _1 collection
111+
112+
_1->toInteger() |-->Integer.parseInt(_1).intValue()<when> _1 String
113+
_1->toReal() |-->Double.parseDouble(_1).doubleValue()<when> _1 String
114+
_1->toUpper() |-->_1.toUpperCase()<when> _1 String
115+
_1->toLower() |-->_1.toLowerCase()<when> _1 String
116+
_1->characters() |-->Ocl.characters(_1)
117+
118+
_1->oclIsUndefined() |-->(_1 == null)
119+
_1->oclIsKindOf(_2) |-->(_1 instanceof _2)
120+
_1->oclAsType(_2) |-->((_2) _1)
121+
_1->allInstances() |-->_1._1_allInstances
122+
123+
_1->first() |-->Ocl.first(_1)
124+
_1->last() |-->Ocl.last(_1)
125+
_1->tail() |-->Ocl.tail(_1)
126+
_1->front() |-->Ocl.front(_1)
127+
_1->reverse() |-->Ocl.reverse(_1)
128+
_1->max() |-->Ocl.max(_1)
129+
_1->min() |-->Ocl.min(_l)
130+
_1->sum() |-->Ocl.sum_1`elementType(_1)
131+
_1->prd() |-->Ocl.prd_1`elementType(_1)
132+
_1->sort() |-->Ocl.sort(_1)
133+
_1->any() |-->Ocl.any(_1)
134+
_1->isEmpty() |-->(_1.size() == 0)
135+
_1->notEmpty() |-->(_1.size() > 0)
136+
_1->asSet() |-->Ocl.asSet(_1)
137+
_1->asSequence() |-->Ocl.asSequence(_1)
138+
_1->flatten() |-->Ocl.flatten(_1)
139+
_1->values() |-->_1.values()
140+
_1->keys() |-->_1.keySet()
141+
142+
143+
not(_1) |-->!(_1)
144+
_1->display() |--> System.out.println(_1 + "");
145+
146+
147+
BinaryExpression::
148+
_1 & _2 |-->_1 && _2
149+
_1 or _2 |-->_1 || _2
150+
_1 xor _2 |-->((_1 || _2) && !(_1 && _2))
151+
152+
_1 = _2 |-->_1 == _2<when> _1 not String, _1 not object, _1 not collection
153+
_1 = _2 |-->_1.equals(_2)<when> _1 String
154+
_1 = _2 |-->_1.equals(_2)<when> _1 object
155+
_1 = _2 |-->_1.equals(_2)<when> _1 Sequence, _2 collection
156+
_1 = _2 |-->Ocl.equalsSet(_1,_2) <when> _1 Set, _2 collection
157+
_1 < _2 |-->_1 < _2<when> _1 numeric, _2 numeric
158+
_1 < _2 |-->(_1.compareTo(_2) < 0)<when> _1 String, _2 String
159+
_1 > _2 |-->_1 > _2<when> _1 numeric, _2 numeric
160+
_1 > _2 |-->(_1.compareTo(_2) > 0)<when> _1 String, _2 String
161+
_1 <= _2 |-->_1 <= _2<when> _1 numeric, _2 numeric
162+
_1 <= _2 |-->(_1.compareTo(_2) <= 0)<when> _1 String, _2 String
163+
_1 >= _2 |-->_1 >= _2<when> _1 numeric, _2 numeric
164+
_1 >= _2 |-->(_1.compareTo(_2) >= 0)<when> _1 String, _2 String
165+
_1 + _2 |-->_1 + _2
166+
_1 - _2 |-->_1 - _2<when> _1 numeric, _2 numeric
167+
_1 - _2 |-->Ocl.subtract(_1,_2)<when> _1 String, _2 String
168+
_1 - _2 |-->Ocl.subtract(_1,_2)<when> _1 Set, _2 collection
169+
_1 - _2 |-->Ocl.subtract(_1,_2)<when> _1 Sequence, _2 collection
170+
_1 * _2 |-->_1 * _2
171+
_1 / _2 |-->_1 / _2
172+
_1 mod _2 |-->_1 % _2
173+
174+
_1->pow(_2) |-->Math.pow(_1,_2)
175+
_1^_2 |-->Ocl.concatenate(_1,_2)
176+
_1->union(_2) |-->Ocl.union(_1,_2)
177+
_1->unionAll(_2|_3) |-->Ocl.unionAll(_1,(_2)->{return _3;})
178+
_1->intersection(_2) |-->Ocl.intersection(_1,_2)
179+
_1->intersectAll(_2|_3) |-->Ocl.intersectAllSet(_1,(_2)->{return _3;})<when> _3 Set
180+
_1->intersectAll(_2|_3) |-->Ocl.intersectAllSequence(_1,(_2)->{return _3;})<when> _3 Sequence
181+
_1->count(_2) |-->Collections.frequency(_1,_2)
182+
183+
_1->at(_2) |-->(_1.charAt(_2) + "")<when> _1 String
184+
_1->at(_2) |-->((_1`elementType) _1.get(_2 - 1))<when> _2 numeric
185+
_1->at(_2) |-->(_1`elementType) _1.get(_2))<when> _2 not numeric
186+
187+
188+
_1->select(_2 | _3) |-->Ocl.selectSet(_1,(_2)->{return _3;})<when> _1 Set
189+
_1->select(_2 | _3) |-->Ocl.selectSequence(_1,(_2)->{return _3;})<when> _1 Sequence
190+
_1->reject(_2 | _3) |-->Ocl.rejectSet(_1,(_2)->{return _3;})<when> _1 Set
191+
_1->reject(_2 | _3) |-->Ocl.rejectSequence(_1,(_2)->{return _3;})<when> _1 Sequence
192+
_1->collect(_2 | _3) |-->Ocl.collectSet(_1,(_2)->{return _3;})<when> _1 Set
193+
_1->collect(_2 | _3) |-->Ocl.collectSequence(_1,(_2)->{return _3;})<when> _1 Sequence
194+
_1->sortedBy(_2|_3) |-->Ocl.sortedBy(_1, Ocl.collectSequence(_1, (_2)->{ return _3; }))
195+
196+
_1->any(_2|_3) |-->Ocl.any(_1._1_allInstances, (_2)->{ return _3; })<when> _1 classId
197+
_1->any(_2|_3) |-->Ocl.any(_1, (_2)->{ return _3; })<when> _1 not classId
198+
199+
200+
_1->forAll(_2 | _3) |-->Ocl.forAll(_1._1_allInstances, (_2)->{ return _3; })<when>_1 classId
201+
_1->forAll(_2 | _3) |-->Ocl.forAll(_1, (_2)->{ return _3; })<when>_1 not classId
202+
203+
_1->exists(_2 | _3) |-->Ocl.exists(_1._1_allInstances, (_2)->{ return _3; })<when> _1 classId
204+
_1->exists(_2 | _3) |-->Ocl.exists(_1, (_2)->{ return _3; })<when> _1 not classId
205+
206+
_1->exists1(_2 | _3) |-->Ocl.exists1(_1._1_allInstances, (_2)->{ return _3; })<when> _1 classId
207+
_1->exists1(_2 | _3) |-->Ocl.exists1(_1, (_2)->{ return _3; })<when> _1 not classId
208+
209+
_1->isUnique(_2 | _3) |-->Ocl.isUnique(Ocl.collectSequence(_1, (_2)->{ return _3; }))
210+
211+
_1 : _2 |-->_2.contains(_1)
212+
_1 <: _2 |-->_2.containsAll(_1)
213+
_1 /: _2 |-->!(_2.contains(_1))
214+
_1->includes(_2) |-->_1.contains(_2)
215+
_1->includesAll(_2) |-->_1.containsAll(_2)
216+
_1->excludes(_2) |-->!(_1.contains(_2))
217+
_1->excludesAll(_2) |-->Collections.disjoint(_1,_2)
218+
219+
_1->including(_2) |-->Ocl.includingSet(_1,_2)<when> _1 Set
220+
_1->including(_2) |-->Ocl.includingSequence(_1,_2)<when> _1 Sequence
221+
_1->prepend(_2) |-->Ocl.prepend(_1,_2)
222+
_1->append(_2) |-->Ocl.append(_1,_2)
223+
_1->excluding(_2) |-->Ocl.excludingSet(_1,_2)<when> _1 Set
224+
_1->excluding(_2) |-->Ocl.excludingSequence(_1,_2)<when> _1 Sequence
225+
226+
_1->hasPrefix(_2) |-->_1.startsWith(_2)
227+
_1->hasSuffix(_2) |-->_1.endsWith(_2)
228+
_1->after(_2) |-->Ocl.after(_1,_2))
229+
_1->before(_2) |-->Ocl.before(_1,_2)
230+
_1->matches(_2) |-->java.util.regex.Pattern.matches(_2,_1)
231+
232+
233+
234+
235+
SetExpression::
236+
Set{} |-->(new HashSet())
237+
Set{_1} |-->Ocl.initialiseSet(_1)
238+
Sequence{} |-->(new ArrayList())
239+
Sequence{_1} |-->Ocl.initialiseSequence(_1)
240+
Map{} |-->(new HashMap())
241+
242+
243+
ConditionalExpression::
244+
if _1 then _2 else _3 endif |-->((_1)?_2:_3)
245+
246+
247+
Class::
248+
class _1 { _2 } |-->interface _1 { _2`cginterface }\n<when> _1 interface
249+
250+
251+
class _1 { _2 } |-->class _1 { static ArrayList<_1> _1_allInstances = new ArrayList<_1>();\n\n _1() { _1_allInstances.add(this); }\n\n static _1 create_1() { _1 result = new _1();\n return result; }\n\n_2}\n
252+
253+
254+
class _1 extends _2 { _3 } |-->class _1 extends _2 { static ArrayList<_1> _1_allInstances = new ArrayList<_1>();\n\n _1() { super();\n _1_allInstances.add(this); }\n\n static _1 create_1() { _1 result = new _1();\n return result; }\n\n_3}\n
255+
256+
257+
class _1 implements _2 { _3 } |-->class _1 implements _2 { static ArrayList<_1> _1_allInstances = new ArrayList<_1>();\n\n _1() { _1_allInstances.add(this); }\n\n static _1 create_1() { _1 result = new _1();\n return result; }\n\n_3}\n
258+
259+
260+
class _1 extends _2 implements _3 { _4 } |-->class _1 extends _2 implements _3 { static ArrayList<_1> _1_allInstances = new ArrayList<_1>();\n\n _1() { super();\n _1_allInstances.add(this); }\n\n static _1 create_1() { _1 result = new _1();\n return result; }\n\n_4}\n
261+
262+
263+
abstract class _1 { _2 } |-->abstract class _1 { static ArrayList<_1> _1_allInstances = new ArrayList<_1>();\n _1() { _1_allInstances.add(this); }\n\n_2}\n
264+
265+
266+
abstract class _1 extends _2 { _3 } |-->abstract class _1 extends _2 { static ArrayList<_1> _1_allInstances = new ArrayList<_1>();\n\n _1() { super();\n _1_allInstances.add(this); }\n\n_3}\n
267+
268+
269+
abstract class _1 implements _2 { _3 } |-->abstract class _1 implements _2 { static ArrayList<_1> _1_allInstances = new ArrayList<_1>();\n\n _1() { _1_allInstances.add(this); }\n\n_3}\n
270+
271+
272+
abstract class _1 extends _2 implements _3 { _4 } |-->abstract class _1 extends _2 implements _3 { static ArrayList<_1> _1_allInstances = new ArrayList<_1>();\n\n _1() { super();\n _1_allInstances.add(this); }\n\n_4}\n
273+
274+
275+
276+
Attribute::
277+
static attribute _1 : _2; |--> static _2 _1 = _2`defaultValue;\n
278+
279+
identity attribute _1 : _2 |--> _2 _1 = _2`defaultValue; /* primary */\n static Map<_2,_1`ownername> _1`ownername_index = new HashMap<_2,_1`ownername>();\n\n static _1`ownername createByPK_1`ownername(_2 _1x) { _1`ownername result = new _1`ownername();\n _1`ownername._1`ownername_index.put(_1x,result);\n result._1 = _1x;\n return result; }\n\n<when> _1 primary
280+
281+
identity attribute _1 : _2; |--> _2 _1 = _2`defaultValue; /* key */\n
282+
283+
attribute _1 : _2; |--> _2 _1 = _2`defaultValue;\n
284+
285+
reference _1 : _2; |--> _2 _1 = new _2();\n<when> _2 collection
286+
287+
reference _1 : _2; |--> _2 _1 = null;\n<when> _2 not collection
288+
289+
290+
291+
292+
Parameter::
293+
_1 : _2, _3 |-->_2 _1, _3
294+
_1 : _2 |-->_2 _1
295+
296+
297+
ParameterArgument::
298+
_1, _2 |-->_1, _2
299+
_1 |-->_1
300+
301+
302+
303+
Operation::
304+
query _1(_2) : _3 pre: _4 post: _5 activity: _6 |-->\n public _3 _1(_2)\n {\n_6 }\n\n
305+
306+
operation _1(_2) : _3 pre: _4 post: _5 activity: _6 |-->\n public _3 _1(_2)\n {\n_6 }\n\n
307+
308+
static query _1(_2) : _3 pre: _4 post: _5 activity: _6 |-->\n public static _3 _1(_2)\n {\n_6 }\n\n
309+
310+
static operation _1(_2) : _3 pre: _4 post: _5 activity: _6 |-->\n public static _3 _1(_2)\n {\n_6 }\n\n
311+
312+
313+
314+
Statement::
315+
316+
_1 := _2 |--> _1 = Ocl.copySet(_2);\n<when> _1 Set
317+
318+
_1 := _2 |--> _1 = Ocl.copySequence(_2);\n<when> _1 Sequence
319+
320+
_1 := _2 |--> _1 = _2;\n
321+
322+
323+
while _1 do _2 |--> while (_1)\n {\n _2 }\n
324+
for _1 : _2 do _3 |--> for (_2`elementType _1 : _2)\n {\n _3 }\n
325+
326+
if _1 then _2 else _3 |--> if (_1)\n {\n _2 }\n else {\n _3 }\n
327+
328+
329+
_1 ; _2 |-->_1_2
330+
skip |--> {}\n
331+
return _1 |--> return _1;\n
332+
return |--> return;\n
333+
break |--> break;\n
334+
call _1 |--> _1;\n
335+
execute _1 |--> /* Abstract statement: _1 */\n
336+
var _1 : _2 |--> _2 _1 = null;\n<when> _2 Class
337+
var _1 : _2 |--> _2 _1 = null;\n<when> _2 collection
338+
var _1 : _2 |--> _2 _1 = _2`defaultValue;\n
339+
340+
341+
342+
UseCase::
343+
usecase _1(_2) : _3 { _4 } |--> public static _3 _1(_2)\n {\n_4 }
344+

0 commit comments

Comments
 (0)