Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9b27a0001dbb3c81b5cca8b5ebb6fb90eab91956 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*******************************************************************************
 * Copyright (c) 2009, 2020 Borland Software Corporation, CEA LIST, Artal & others
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/ 
 * 
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors: 
 *    Artem Tikhomirov (Borland) - initial API and implementation
 *    Guillaume Hillairet (Montages A.G.)
 *    Aurelien Didier (ARTAL) - aurelien.didier51@gmail.com - Bug 569174
 */
library ModelFacets;

import Utils;
import ValueExpressions;
import Parsers;

modeltype GMFMAP uses mappings('http://www.eclipse.org/papyrus/gmf/2020/mappings');
modeltype GMFTOOL uses tooldef('http://www.eclipse.org/papyrus/gmf/2020/ToolDefinition');
modeltype GMFGEN uses gmfgen('http://www.eclipse.org/papyrus/gmf/2020/GenModel');
modeltype GMFGRAPH uses gmfgraph('http://www.eclipse.org/papyrus/gmf/2020/GraphicalDefinition');
modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore');
modeltype GENMODEL uses genmodel('http://www.eclipse.org/emf/2002/GenModel');

--	
--	TypeModelFacet
--

helper GMFMAP::NodeReference::createModelFacet() : GMFGEN::TypeModelFacet {
	if self.child.domainMetaElement.oclIsUndefined() then return null endif;
	var mf := object TypeModelFacet {};
	
	mf.metaClass := self.child.domainMetaElement.findGenClass();
	mf.containmentMetaFeature := self.containmentFeature.findGenFeature();
	
	if self.childrenFeature.oclIsUndefined() then 
		mf.childMetaFeature := mf.containmentMetaFeature 
	else 
		mf.childMetaFeature := self.childrenFeature.findGenFeature() 
	endif;
	
	mf.modelElementSelector := self.child.domainSpecialization.map createConstraint(); 
	mf.modelElementInitializer := self.child.domainInitializer.map structure();
	return mf;
}

--
--	LinkModelFacet
--

mapping GMFMAP::LinkMapping::createModelFacet(): GMFGEN::LinkModelFacet 
	disjuncts 
		GMFMAP::LinkMapping::createFeatureLinkModelFacet,
		GMFMAP::LinkMapping::createTypeLinkModelFacet
	{}

mapping GMFMAP::LinkMapping::createFeatureLinkModelFacet() : GMFGEN::FeatureLinkModelFacet 
when {
	self.domainMetaElement.oclIsUndefined() and not self.linkMetaFeature.oclIsUndefined()
}
{	
	metaFeature := self.linkMetaFeature.findGenFeature();
}

mapping GMFMAP::LinkMapping::createTypeLinkModelFacet() : GMFGEN::TypeLinkModelFacet 
when {
	not self.domainMetaElement.oclIsUndefined()
} 
{	
	metaClass := self.domainMetaElement.findGenClass();
	containmentMetaFeature := self.containmentFeature.findGenFeature();
	childMetaFeature := containmentMetaFeature;
	sourceMetaFeature := self.sourceMetaFeature.findGenFeature();
	targetMetaFeature := self.linkMetaFeature.findGenFeature();
	modelElementSelector := self.domainSpecialization.map createConstraint(); -- ALTERNATIVE: if not self.domainSpecialization.oclIsUndefined() then modelElementSelector := self.domainSpecialization.map structure() endif; 
	modelElementInitializer := self.domainInitializer.map structure();
}

--
--	LabelModelFacet
--

mapping GMFMAP::LabelMapping::createLabelModelFacet(node: NeedsContainment) : GMFGEN::LabelModelFacet 
	disjuncts 
		GMFMAP::LabelMapping::createDefaultLabelModelFacet,
		GMFMAP::FeatureLabelMapping::createFeatureLabelModelFacet,
		GMFMAP::DesignLabelMapping::createDesignLabelModelFacet,
		GMFMAP::ExpressionLabelMapping::createExpressionLabelModelFacet,
		GMFMAP::OclChoiceLabelMapping::createOclChoiceLabelModelFacet
	{}

mapping GMFMAP::LabelMapping::createDefaultLabelModelFacet(node: NeedsContainment) : GMFGEN::LabelModelFacet 
	when {self.oclIsTypeOf(LabelMapping)} 
{
--	init {
--		if auxParser = null then 
--			auxParser := object GMFGEN::ExternalParser {}
--		endif;
--	}
--	parser := auxParser;
	parser := self.map createExternalParser();
}

mapping GMFMAP::FeatureLabelMapping::createFeatureLabelModelFacet(node: NeedsContainment) : GMFGEN::FeatureLabelModelFacet {
	metaFeatures += self.features.findGenFeature();
	editableMetaFeatures += self.editableFeatures.findGenFeature();
	viewPattern := self.viewPattern;
	editPattern := self.editPattern;
	editorPattern := self.editorPattern;
	viewMethod := self.viewMethod.convertLabelTextAccessMethod();
	editMethod := self.editMethod.convertLabelTextAccessMethod();
	
	parser := if self.isEnumLabelMapping() then self.getOrCreateEnumParser() else self.getOrCreatePredefinedParser() endif;
}

mapping GMFMAP::DesignLabelMapping::createDesignLabelModelFacet(node: NeedsContainment) : GMFGEN::DesignLabelModelFacet {
--	if designLabelParser = null then 
--		designLabelParser := object GMFGEN::ExternalParser {} 
--	endif;	
--	parser := designLabelParser;
	parser := self.map createExternalParser();
}

mapping GMFMAP::ExpressionLabelMapping::createExpressionLabelModelFacet(node: NeedsContainment): GMFGEN::ExpressionLabelModelFacet {
	parser := self.map createExpressionLabelParser();
}

mapping GMFMAP::OclChoiceLabelMapping::createOclChoiceLabelModelFacet(node: NeedsContainment): GMFGEN::FeatureLabelModelFacet {
	var genFeature = self.feature.findGenFeature();  
	metaFeatures += genFeature;
	editableMetaFeatures += genFeature;
	parser := self.map createOclChoiceParser();
}

-- 
-- FeatureInitializer
-- 

mapping GMFMAP::FeatureInitializer::structure() : GMFGEN::GenFeatureInitializer {
	init {
		assert (false) with log ('No idea how to process FeatureInitializer', self);
	}
}

mapping GMFMAP::FeatureValueSpec::structure() : GMFGEN::GenFeatureInitializer {
	init {
		result := object GenFeatureValueSpec {
			feature := self.feature.findGenFeature();
			value := self.value.map createValueExpression();
		}
	}
}

mapping GMFMAP::ReferenceNewElementSpec::structure() : GMFGEN::GenFeatureInitializer {
	init {
		result := object GenReferenceNewElementSpec {
			feature := self.feature.findGenFeature();
			-- cast to GenFeatureSeqInitializer was in the original DGMT
			newElementInitializers += self.newElementInitializers.map structure().oclAsType(GMFGEN::GenFeatureSeqInitializer);
		}
	}
}

-- 
-- ElementInitializer
-- 

mapping GMFMAP::ElementInitializer::structure() : GMFGEN::GenElementInitializer {
	init {
		assert (false) with log ('No idea how to process ElementInitializer', self);
	}
}

mapping GMFMAP::FeatureSeqInitializer::structure() : GMFGEN::GenElementInitializer {
	init {
		result := object GenFeatureSeqInitializer {
			initializers += self.initializers.map structure();
			if not self.elementClass.oclIsUndefined() then
				elementClass := self.elementClass.findGenClass()
			endif;
		}
	}
}

--	
--	Queries
--	

query GMFMAP::ValueExpression::selectProvider(mapRoot: GMFMAP::Mapping): GenExpressionProviderBase =
	mapRoot->resolveone(GMFGEN::GenExpressionProviderContainer).providers->any(e | 
		e.getLanguage().equals(self.language)
	);

query GenLanguage::equals(lang: Language) : Boolean = self.repr() = lang.repr();

query GMFMAP::LabelTextAccessMethod::convertLabelTextAccessMethod() : GMFGEN::LabelTextAccessMethod =
	switch {
		case (self = GMFMAP::LabelTextAccessMethod::NATIVE) return GMFGEN::LabelTextAccessMethod::NATIVE;
		case (self = GMFMAP::LabelTextAccessMethod::REGEXP) return GMFGEN::LabelTextAccessMethod::REGEXP;
		case (self = GMFMAP::LabelTextAccessMethod::PRINTF) return GMFGEN::LabelTextAccessMethod::PRINTF;
		else return GMFGEN::LabelTextAccessMethod::MESSAGE_FORMAT;
	};

Back to the top