blob: b31e2eaedb690ded720b4bb367d20d9ea1db7ac0 (
plain) (
blame)
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
|
/*******************************************************************************
* Copyright (c) 2010 protos software gmbh (http://www.protos.de).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* CONTRIBUTORS:
* Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
*
*******************************************************************************/
import ecore;
import xtext;
process(xtext::GeneratedMetamodel this) :
process(ePackage)
;
// the multiplicity is an optional attribute with a default of 1
process(ecore::EPackage this) :
this.eClassifiers.typeSelect(ecore::EClass).process()
;
process(EClass this) :
switch (name) {
case "Port": (eAllAttributes.select(e|e.name=="multiplicity").first().setDefaultValueLiteral("1")
-> addOperation("isReplicated", getEcoreDataType("EBoolean")))
case "State": (addOperation("getName", getEcoreDataType("EString")))
case "StateGraphItem": (addOperation("getName", getEcoreDataType("EString")))
default: null
}
;
EDataType getEcoreDataType(String name) :
org::eclipse::emf::ecore::EcorePackage::eINSTANCE.getEClassifier(name)
;
addOperation(EClass this, String name, EClassifier type) :
let op = newOperation(name, type) :
newDelegatingBodyAnnotation(this, op)
;
create EOperation newOperation(EClass owner, String name, EClassifier type) :
setName(name) -> setEType(type) -> owner.eOperations.add(this)
;
create EAnnotation newDelegatingBodyAnnotation(EClass cls, EOperation op) :
let d = new EStringToStringMapEntry :
setSource("http://www.eclipse.org/emf/2002/GenModel") ->
d.setKey("body") ->
switch (op.name) {
case "getName":
(switch (cls.name) {
case "State":
(d.setValue("return (this instanceof org.eclipse.etrice.core.room.BaseState)? "
+"((org.eclipse.etrice.core.room.BaseState)this).getName() :"
+"((org.eclipse.etrice.core.room.RefinedState)this).getBase()==null?"
+" \"\":((org.eclipse.etrice.core.room.RefinedState)this).getBase().getName();"))
case "StateGraphItem":
(d.setValue("if (this instanceof org.eclipse.etrice.core.room.State) return ((org.eclipse.etrice.core.room.State)this).getName();\n"
+ "else if (this instanceof org.eclipse.etrice.core.room.TrPoint) return ((org.eclipse.etrice.core.room.TrPoint)this).getName();\n"
+ "else if (this instanceof org.eclipse.etrice.core.room.ChoicePoint) return ((org.eclipse.etrice.core.room.ChoicePoint)this).getName();\n"
+ "else if (this instanceof org.eclipse.etrice.core.room.Transition) return ((org.eclipse.etrice.core.room.Transition)this).getName();\n"
+ "return \"\";"))
default: null
})
case "isReplicated":
(d.setValue("return multiplicity>1 || multiplicity==-1;"))
default: null
} ->
details.add(d) ->
op.eAnnotations.add(this)
;
|