Skip to main content
summaryrefslogtreecommitdiffstats
blob: f1d2381bf0573d1812bba2c8bfbcb5f4c034c5c9 (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
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
modeltype Ecore uses "http://www.eclipse.org/emf/2002/Ecore";
modeltype PropertyContext uses "http://www.eclipse.org/papyrus/properties/contexts/0.9";
modeltype PropertyEnvironment uses "http://www.eclipse.org/papyrus/properties/environment/0.9";
modeltype PRoot uses "http://www.eclipse.org/papyrus/properties/root";
modeltype Constraints uses "http://www.eclipse.org/papyrus/constraints/0.9";

transformation ecore2datacontext(in ecore : Ecore,in list: Ecore,in pRoot : PRoot, out context : PropertyContext);

main() {
	ecore.rootObjects()[EPackage]->map toContext();
}

mapping EPackage::toContext() : c: Context, root:DataContextRoot when {
	//self.isMainPackage() //Only transform source EPackages ; not their dependencies
self.isSelected() 
}{
	log("Package " + self.name);
	c.name := self.name;
	c.dataContexts := root;
	c.views := self.eClassifiers->select(e | e.oclIsKindOf(EClass))->map toDataContextElement().viewSingle
		->union(self.eClassifiers->select(e | e.oclIsKindOf(EClass))->map toDataContextElement().viewMultiple);
	
	root.name := self.name;
	root.label := self.name;
	root.elements := self.eClassifiers->select(e | e.oclIsKindOf(EClass))->map toDataContextElement().element
				->union(self.eSubpackages->map toDataContextPackage());
	
	root.modelElementFactory := pRoot.rootObjects()[PropertiesRoot].environments.modelElementFactories
		->any(e | e.factoryClass = 'org.eclipse.papyrus.views.properties.modelelement.EMFModelElementFactory');
}

mapping EPackage::toDataContextPackage() : DataContextPackage{
	name := self.name;
	elements := self.eClassifiers->select(e | e.oclIsKindOf(EClass))->map toDataContextElement().element
					->union(self.eSubpackages->map toDataContextPackage());
}

query EPackage::getRootPackage() : EPackage {
	var package : EPackage;
	if self.eSuperPackage.oclIsUndefined() then 
		package := self
	else
		package := self.eSuperPackage.getRootPackage()
	endif;
	return package;
}

query EClass::getRootPackage() : EPackage {
	return self.ePackage.getRootPackage();
}

query EClass::getContext() : PropertyContext::Context {
	return self.getRootPackage().map toContext().c;
}

abstract mapping EClassifier::toDataContextElement() : element : DataContextElement, viewSingle : View, viewMultiple : View {
	element.name := self.name;
}

mapping EClass::toDataContextElement() : element : DataContextElement, viewSingle : View, viewMultiple : View  inherits EClassifier::toDataContextElement 
when {
	self.ePackage.isSelected() 
}
{

	element.properties := self.eStructuralFeatures->map toProperty(); 
	element.supertypes := self.eSuperTypes.map toDataContextElement().element;

	viewSingle.name := 'Single '+self.name;
	viewSingle.automaticContext := true;
	viewSingle.datacontexts := element;
	viewSingle.elementMultiplicity := 1;
	viewSingle.constraints := self.map toConstraint(viewSingle);
	viewSingle.context := self.getContext();
	
	viewMultiple.name := 'Multiple '+self.name;
	viewMultiple.automaticContext := true;
	viewMultiple.datacontexts := element;
	viewMultiple.elementMultiplicity := -1;
	viewMultiple.constraints := self.map toConstraint(viewMultiple);
	viewMultiple.context := self.getContext();
}

query EPackage::isMainPackage() : Boolean {
	return if ecore.rootObjects()->includes(self) then 
		true 
	else 
		if self.eSuperPackage.oclIsUndefined() then
			false
		else
			self.eSuperPackage.isMainPackage()
		endif
	endif;
}

query EPackage::isSelected() : Boolean {
 	
 	return if (list.objectsOfType(EPackage)->includes(self.getRootPackage())) then  true
	else false
	endif;
}
mapping EClass::toConstraint(view : View) : SimpleConstraint {
	name := "is" + view.name.replace(' ', '');
	display := view;
	constraintType := pRoot.objectsOfType(PropertiesRoot).environments.constraintTypes->any(e | e.constraintClass = 'org.eclipse.papyrus.infra.constraints.constraints.EMFInstanceOfConstraint');
	var className := object ValueProperty {
		name := 'className';
		value := self.name;
	};
	var nsUri := object ValueProperty {
		name := 'nsUri';
		value := self.ePackage.nsURI;
	};
	properties := Set{className, nsUri};
}

mapping EStructuralFeature::toProperty() : Property {
	name := self.name;
	type := self.eType.toType();
	multiplicity := if self.upperBound = 1 then 1 else -1 endif;
	description := self.getGenModelDocumentation();
	//multiplicity := self.upperBound;
}

query EModelElement::getGenModelDocumentation() : String {
	return self.eAnnotations->select(e | e.source = 'http://www.eclipse.org/emf/2002/GenModel').details->any(entry | entry.key = 'documentation').value;
}

query EClassifier::toType() : Type {
	log("Unknown type : "+self.repr());
	return null;
}

query EClass::toType() : Type {
	return Type::Reference;
}

query EEnum::toType() : Type {
	return Type::Enumeration;
}

query EDataType::toType() : Type {
	var type : Type;
	switch {
		case (self.instanceClassName = "java.lang.String") type := Type::String; 
		case (self.instanceClassName = "int") type := Type::Integer;
		case (self.instanceClassName = "boolean") type := Type::Boolean;
	};
	if type.oclIsUndefined() then {
		log("Type : "+self.name);
		log("Instance : "+self.instanceClassName);
		type := Type::String;
	}endif;
	return type;
}

Back to the top