Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1b5a562200b1c7836d32a15f7244667d0d69b44c (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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
import  cs : 'ClassesCS.ecore#/'
import  as : 'Classes.ecore#/'
import 'EnvExample2.ecore'
import 'classescs2asV2Helpers.ocl'

package ocl

context OclElement
-- Domain specific default functionality
def : unqualified_env_Class() : lookup::LookupEnvironment[1] =
	_unqualified_env_Class(null)
def : unqualified_env_Package() : lookup::LookupEnvironment[1] =
	_unqualified_env_Package(null)
def : unqualified_env_Operation() : lookup::LookupEnvironment[1] =
	_unqualified_env_Operation(null)
def : unqualified_env_Property() : lookup::LookupEnvironment[1] =
	_unqualified_env_Property(null)

def : _unqualified_env_Class(child : OclElement) : lookup::LookupEnvironment[1] =
	parentEnv_Class()
def : _unqualified_env_Package(child : OclElement) : lookup::LookupEnvironment[1] =
	parentEnv_Package()
def : _unqualified_env_Operation(child : OclElement) : lookup::LookupEnvironment[1] =
	parentEnv_Operation()
def : _unqualified_env_Property(child : OclElement) : lookup::LookupEnvironment[1] =
	parentEnv_Property()

def : parentEnv_Class() : lookup::LookupEnvironment[1] =
	let parent = oclContainer() in if parent = null then lookup::LookupEnvironment { } else parent._unqualified_env_Class(self) endif
def : parentEnv_Package() : lookup::LookupEnvironment[1] =
	let parent = oclContainer() in if parent = null then lookup::LookupEnvironment { } else parent._unqualified_env_Package(self) endif
def : parentEnv_Operation() : lookup::LookupEnvironment[1] =
	let parent = oclContainer() in if parent = null then lookup::LookupEnvironment { } else parent._unqualified_env_Operation(self) endif
def : parentEnv_Property() : lookup::LookupEnvironment[1] =
	let parent = oclContainer() in if parent = null then lookup::LookupEnvironment { } else parent._unqualified_env_Property(self) endif

def : _exported_env_Operation(importer : OclElement) : lookup::LookupEnvironment[1] =
	lookup::LookupEnvironment { }
def : _exported_env_Property(importer : OclElement) : lookup::LookupEnvironment[1] =
	lookup::LookupEnvironment { }
	
def : _qualified_env_Class(child : OclElement) : lookup::LookupEnvironment[1] =
	lookup::LookupEnvironment { }
def : _qualified_env_Package(child : OclElement) : lookup::LookupEnvironment[1] =
	lookup::LookupEnvironment { }
def : _qualified_env_Operation(child : OclElement) : lookup::LookupEnvironment[1] =
	lookup::LookupEnvironment { }
def : _qualified_env_Property(child : OclElement) : lookup::LookupEnvironment[1] =
	lookup::LookupEnvironment { }
-- End of domain specific default functionality
endpackage 

package lookup
-- Some common lookup functionality
context LookupEnvironment
def : nestedEnv() : LookupEnvironment[1] =
	LookupEnvironment {
		parentEnv = self
	}
-- End of common lookup functionality
endpackage

package as

	
context Root
def : _unqualified_env_Package(child : ocl::OclElement) : lookup::LookupEnvironment =
	parentEnv_Package().nestedEnv()
		.addElements(ownedPackages)
		
	
context Package
	
def : _lookupQualifiedPackage(pName : String) : Package[?] =
	let foundPackage = _lookupPackage(_qualified_env_Package(), pName)
	in  if foundPackage->isEmpty()
		then null
		else foundPackage->first()
		endif
def : _qualified_env_Package() : lookup::LookupEnvironment =
	let env = lookup::LookupEnvironment{}
	in env
		.addElements(ownedPackages)
def : lookupQualifiedPackage(aPathElementCS : cs::PathElementCS) : Package[?] =
   _lookupQualifiedPackage(aPathElementCS.name)
   
	
def : _lookupQualifiedClass(cName : String) : Class[?] =
	let foundClass = _lookupClass(_qualified_env_Class(), cName)
	in  if foundClass->isEmpty()
		then null
		else foundClass->first()
		endif
def : _qualified_env_Class() : lookup::LookupEnvironment =
	let env = lookup::LookupEnvironment{}
	in env
		.addElements(ownedClasses)
def : lookupQualifiedClass(aPathElementCS : cs::PathElementCS) : Class[?] =
   _lookupQualifiedClass(aPathElementCS.name)
   
def : _unqualified_env_Package(child : ocl::OclElement) : lookup::LookupEnvironment =
	parentEnv_Package().nestedEnv()
		.addElements(ownedPackages)
		
def : _unqualified_env_Class(child : ocl::OclElement) : lookup::LookupEnvironment =
	parentEnv_Class().nestedEnv()
		.addElements(ownedClasses)
		
	
context Class
	
def : _lookupQualifiedOperation(oName : String, args : OrderedSet(Argument)) : Operation[?] =
	let foundOperation = _lookupOperation(_qualified_env_Operation(), oName, args)
	in  if foundOperation->isEmpty()
		then null
		else foundOperation->first()
		endif
def : _qualified_env_Operation() : lookup::LookupEnvironment =
	let env = lookup::LookupEnvironment{}
	in env
	.addElements(ownedOperations)
def : lookupQualifiedOperation(aPathElementCS : cs::PathElementCS, args : OrderedSet(Argument)) : Operation[?] =
   _lookupQualifiedOperation(aPathElementCS.name, args)
   
	
def : _lookupQualifiedProperty(pName : String) : Property[?] =
	let foundProperty = _lookupProperty(_qualified_env_Property(), pName)
	in  if foundProperty->isEmpty()
		then null
		else foundProperty->first()
		endif
def : _qualified_env_Property() : lookup::LookupEnvironment =
	let env = lookup::LookupEnvironment{}
	in env
	.addElements(ownedProperties)
def : lookupQualifiedProperty(aPathElementCS : cs::PathElementCS) : Property[?] =
   _lookupQualifiedProperty(aPathElementCS.name)
   
def : _unqualified_env_Operation(child : ocl::OclElement) : lookup::LookupEnvironment =
	parentEnv_Operation().nestedEnv()
		.addElements(self->closure(superClass).ownedOperations)
		.nestedEnv()
		.addElements(ownedOperations)
		
def : _unqualified_env_Property(child : ocl::OclElement) : lookup::LookupEnvironment =
	parentEnv_Property().nestedEnv()
		.addElements(self->closure(superClass).ownedProperties)
		.nestedEnv()
		.addElements(ownedProperties)
		
def : _exported_env_Operation(importer : ocl::OclElement) : lookup::LookupEnvironment =
	let env = lookup::LookupEnvironment {}
	in env
		.addElements(ownedOperations)
	
def : _exported_env_Property(importer : ocl::OclElement) : lookup::LookupEnvironment =
	let env = lookup::LookupEnvironment {}
	in env
		.addElements(ownedProperties)
	
	
def : _lookupExportedOperation(importer : ocl::OclElement, oName : String, args : OrderedSet(Argument)) : Operation[?] =
	let foundOperation = _lookupOperation(_exported_env_Operation(importer), oName, args)
	in  if foundOperation->isEmpty()
		then null
		else foundOperation->first()
		endif
		
def : lookupExportedOperation(importer : ocl::OclElement, aPathElementCS : cs::PathElementCS, args : OrderedSet(Argument)) : Operation[?] =
	_lookupExportedOperation(importer, aPathElementCS.name, args)
	
def : _lookupExportedProperty(importer : ocl::OclElement, pName : String) : Property[?] =
	let foundProperty = _lookupProperty(_exported_env_Property(importer), pName)
	in  if foundProperty->isEmpty()
		then null
		else foundProperty->first()
		endif
		
def : lookupExportedProperty(importer : ocl::OclElement, aPathElementCS : cs::PathElementCS) : Property[?] =
	_lookupExportedProperty(importer, aPathElementCS.name)
	
context Operation
	
def : _appliesFilter_Operation(args : OrderedSet(Argument)) : Boolean =
	args->size() = ownedParameters->size() and args->forAll(x | x.name = ownedParameters->at(args->indexOf(x)).name)

context Visitable
-- Package lookup
def : _lookupPackage(env : lookup::LookupEnvironment, pName : String) : OrderedSet(Package) =
let foundPackage = env.getNamedElements(pName)->selectByKind(Package)
in  if foundPackage->isEmpty() and not (env.parentEnv = null)
	then _lookupPackage(env.parentEnv, pName)
	else foundPackage
	endif
	
-- Note: when calling this method, the source element of the argument passed to this method, will be the contextual 
-- object on which error reports will be handled
def : _lookupUnqualifiedPackage(pName : String) : Package[?] =
let foundPackage = _lookupPackage(unqualified_env_Package(), pName)
in  if foundPackage->isEmpty()
	then null
	else foundPackage->first() -- LookupVisitor will report ambiguous result
	endif
def : lookupPackage(aPathElementCS : cs::PathElementCS) : Package[?] =
   _lookupUnqualifiedPackage(aPathElementCS.name)
   

-- QN Package lookup
def : lookupPackage(aPathNameCS : cs::PathNameCS) : Package[?] =
   lookupPackage(aPathNameCS .path)

def : lookupPackage(segments : OrderedSet(cs::PathElementCS)) : Package[?] =
   if segments->size() = 1
   then lookupPackage(segments->first())
   else let qualifierSegments = segments->subOrderedSet(1,segments->size()-1),
            qualifier = lookupPackage(qualifierSegments)
        in qualifier?.lookupQualifiedPackage(segments->last())
   endif

-- Class lookup
def : _lookupClass(env : lookup::LookupEnvironment, cName : String) : OrderedSet(Class) =
let foundClass = env.getNamedElements(cName)->selectByKind(Class)
in  if foundClass->isEmpty() and not (env.parentEnv = null)
	then _lookupClass(env.parentEnv, cName)
	else foundClass
	endif
	
-- Note: when calling this method, the source element of the argument passed to this method, will be the contextual 
-- object on which error reports will be handled
def : _lookupUnqualifiedClass(cName : String) : Class[?] =
let foundClass = _lookupClass(unqualified_env_Class(), cName)
in  if foundClass->isEmpty()
	then null
	else foundClass->first() -- LookupVisitor will report ambiguous result
	endif
def : lookupClass(aPathElementCS : cs::PathElementCS) : Class[?] =
   _lookupUnqualifiedClass(aPathElementCS.name)
   

-- QN Class lookup
def : lookupClass(aPathNameCS : cs::PathNameCS) : Class[?] =
   lookupClass(aPathNameCS .path)

def : lookupClass(segments : OrderedSet(cs::PathElementCS)) : Class[?] =
   if segments->size() = 1
   then lookupClass(segments->first())
   else let qualifierSegments = segments->subOrderedSet(1,segments->size()-1),
            qualifier = lookupPackage(qualifierSegments)
        in qualifier?.lookupQualifiedClass(segments->last())
   endif

-- Class exports Operation
	
def : lookupOperationFrom(exporter : Class, aPathElementCS : cs::PathElementCS, args : OrderedSet(Argument)) : Operation[?] =
	exporter.lookupExportedOperation(self, aPathElementCS, args)

def : lookupOperationFrom(exporter : Class, aPathNameCS : cs::PathNameCS, args : OrderedSet(Argument)) : Operation[?] =
   lookupOperationFrom(exporter, aPathNameCS.path, args)

def : lookupOperationFrom(exporter : Class, segments : OrderedSet(cs::PathElementCS), args : OrderedSet(Argument)) : Operation[?] =
   if segments->size() = 1
   then lookupOperationFrom(exporter, segments->first(), args)
   else let qualifierSegments = segments->subOrderedSet(1,segments->size()-1),
            qualifier = lookupClass(qualifierSegments)
        in qualifier?.lookupQualifiedOperation(segments->last(), args)
   endif
-- Class exports Property
	
def : lookupPropertyFrom(exporter : Class, aPathElementCS : cs::PathElementCS) : Property[?] =
	exporter.lookupExportedProperty(self, aPathElementCS)

def : lookupPropertyFrom(exporter : Class, aPathNameCS : cs::PathNameCS) : Property[?] =
   lookupPropertyFrom(exporter, aPathNameCS.path)

def : lookupPropertyFrom(exporter : Class, segments : OrderedSet(cs::PathElementCS)) : Property[?] =
   if segments->size() = 1
   then lookupPropertyFrom(exporter, segments->first())
   else let qualifierSegments = segments->subOrderedSet(1,segments->size()-1),
            qualifier = lookupClass(qualifierSegments)
        in qualifier?.lookupQualifiedProperty(segments->last())
   endif
-- Operation lookup
def : _lookupOperation(env : lookup::LookupEnvironment, oName : String, args : OrderedSet(Argument)) : OrderedSet(Operation) =
let foundOperation = env.getNamedElements(oName)->selectByKind(Operation)
                                         ->select(_appliesFilter_Operation(args))
in  if foundOperation->isEmpty() and not (env.parentEnv = null)
	then _lookupOperation(env.parentEnv, oName, args)
	else foundOperation
	endif
	
-- Note: when calling this method, the source element of the argument passed to this method, will be the contextual 
-- object on which error reports will be handled
def : _lookupUnqualifiedOperation(oName : String, args : OrderedSet(Argument)) : Operation[?] =
let foundOperation = _lookupOperation(unqualified_env_Operation(), oName, args)
in  if foundOperation->isEmpty()
	then null
	else foundOperation->first() -- LookupVisitor will report ambiguous result
	endif
def : lookupOperation(aPathElementCS : cs::PathElementCS, args : OrderedSet(Argument)) : Operation[?] =
   _lookupUnqualifiedOperation(aPathElementCS.name, args)
   

-- QN Operation lookup
def : lookupOperation(aPathNameCS : cs::PathNameCS, args : OrderedSet(Argument)) : Operation[?] =
   lookupOperation(aPathNameCS .path, args)

def : lookupOperation(segments : OrderedSet(cs::PathElementCS), args : OrderedSet(Argument)) : Operation[?] =
   if segments->size() = 1
   then lookupOperation(segments->first(), args)
   else let qualifierSegments = segments->subOrderedSet(1,segments->size()-1),
            qualifier = lookupClass(qualifierSegments)
        in qualifier?.lookupQualifiedOperation(segments->last(), args)
   endif

-- Property lookup
def : _lookupProperty(env : lookup::LookupEnvironment, pName : String) : OrderedSet(Property) =
let foundProperty = env.getNamedElements(pName)->selectByKind(Property)
in  if foundProperty->isEmpty() and not (env.parentEnv = null)
	then _lookupProperty(env.parentEnv, pName)
	else foundProperty
	endif
	
-- Note: when calling this method, the source element of the argument passed to this method, will be the contextual 
-- object on which error reports will be handled
def : _lookupUnqualifiedProperty(pName : String) : Property[?] =
let foundProperty = _lookupProperty(unqualified_env_Property(), pName)
in  if foundProperty->isEmpty()
	then null
	else foundProperty->first() -- LookupVisitor will report ambiguous result
	endif
def : lookupProperty(aPathElementCS : cs::PathElementCS) : Property[?] =
   _lookupUnqualifiedProperty(aPathElementCS.name)
   

-- QN Property lookup
def : lookupProperty(aPathNameCS : cs::PathNameCS) : Property[?] =
   lookupProperty(aPathNameCS .path)

def : lookupProperty(segments : OrderedSet(cs::PathElementCS)) : Property[?] =
   if segments->size() = 1
   then lookupProperty(segments->first())
   else let qualifierSegments = segments->subOrderedSet(1,segments->size()-1),
            qualifier = lookupClass(qualifierSegments)
        in qualifier?.lookupQualifiedProperty(segments->last())
   endif



endpackage

Back to the top