Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 843e0db50b77c4fe593bdc88f53823666b5f999d (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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
import  cs : 'generated/MiniOCLCS.ecore#/' 
import  as : '/resource/org.eclipse.qvtd.doc.miniocl/model/MiniOCL.ecore#/' 
import '/resource/org.eclipse.qvtd.doc.miniocl/model/Lookup.ecore'
import 'MiniOCLFullHelpers.ocl'

package ocl

-- Domain specific default functionality
context OclElement
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_Variable() : lookup::LookupEnvironment[1] =
	_unqualified_env_Variable(null)
def : unqualified_env_NamedElement() : lookup::LookupEnvironment[1] =
	_unqualified_env_NamedElement(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_Variable(child : OclElement) : lookup::LookupEnvironment[1] =
	parentEnv_Variable()
def : _unqualified_env_NamedElement(child : OclElement) : lookup::LookupEnvironment[1] =
	parentEnv_NamedElement()
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_Variable() : lookup::LookupEnvironment[1] =
	let parent = oclContainer() in if parent = null then lookup::LookupEnvironment { } else parent._unqualified_env_Variable(self) endif
def : parentEnv_NamedElement() : lookup::LookupEnvironment[1] =
	let parent = oclContainer() in if parent = null then lookup::LookupEnvironment { } else parent._unqualified_env_NamedElement(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_Property(importer : OclElement) : lookup::LookupEnvironment[1] =
	lookup::LookupEnvironment { }
def : _exported_env_Operation(importer : OclElement) : lookup::LookupEnvironment[1] =
	lookup::LookupEnvironment { }

def : _qualified_env_Class(qualifier : OclElement) : lookup::LookupEnvironment[1] =
	lookup::LookupEnvironment { }
def : _qualified_env_Package(qualifier : OclElement) : lookup::LookupEnvironment[1] =
	lookup::LookupEnvironment { }
def : _qualified_env_Operation(qualifier : OclElement) : lookup::LookupEnvironment[1] =
	lookup::LookupEnvironment { }
def : _qualified_env_Property(qualifier : 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 Visitable
-- NamedElement unqualified lookup
def : _lookupNamedElement(env : lookup::LookupEnvironment, nName : String) : OrderedSet(NamedElement) =
let foundNamedElement = env.namedElements->selectByKind(NamedElement)->select(name = nName)
in  if foundNamedElement->isEmpty() and not (env.parentEnv = null)
   then _lookupNamedElement(env.parentEnv, nName)
   else foundNamedElement
   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 : _lookupUnqualifiedNamedElement(nName : String) : NamedElement[?] =
let foundNamedElement = _lookupNamedElement(unqualified_env_NamedElement(), nName)
in  if foundNamedElement->isEmpty()
   then null
   else foundNamedElement->first() -- LookupVisitor will report ambiguous result
   endif
   
def : lookupNamedElement(nName : String) : NamedElement[?] =
   _lookupUnqualifiedNamedElement(nName)
def : lookupNamedElement(aPathElementCS : cs::PathElementCS) : NamedElement[?] =
   _lookupUnqualifiedNamedElement(aPathElementCS.elementName)
-- End of NamedElement unqualified lookup 
   
	
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.elementName)
   
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.elementName)
context Visitable
-- Package unqualified lookup
def : _lookupPackage(env : lookup::LookupEnvironment, pName : String) : OrderedSet(Package) =
let foundPackage = env.namedElements->selectByKind(Package)->select(name = pName)
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(pName : String) : Package[?] =
   _lookupUnqualifiedPackage(pName)
def : lookupPackage(aPathElementCS : cs::PathElementCS) : Package[?] =
   _lookupUnqualifiedPackage(aPathElementCS.elementName)
-- End of Package unqualified lookup 
   
-- Package qualified-name lookup
def : lookupPackage(aPathNameCS : cs::PathNameCS) : Package[?] =
   lookupPackage(aPathNameCS .pathElements)
   
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
	
context Class
   
def : _lookupQualifiedOperation(oName : String, arguments : OrderedSet(OCLExpression)) : Operation[?] =
   let foundOperation = _lookupOperation(_qualified_env_Operation(), oName, arguments)
   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, arguments : OrderedSet(OCLExpression)) : Operation[?] =
   _lookupQualifiedOperation(aPathElementCS.elementName, arguments)
   
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.elementName)
context Visitable
-- Class unqualified lookup
def : _lookupClass(env : lookup::LookupEnvironment, cName : String) : OrderedSet(Class) =
let foundClass = env.namedElements->selectByKind(Class)->select(name = cName)
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(cName : String) : Class[?] =
   _lookupUnqualifiedClass(cName)
def : lookupClass(aPathElementCS : cs::PathElementCS) : Class[?] =
   _lookupUnqualifiedClass(aPathElementCS.elementName)
-- End of Class unqualified lookup 
   
-- Class qualified-name lookup
def : lookupClass(aPathNameCS : cs::PathNameCS) : Class[?] =
   lookupClass(aPathNameCS .pathElements)
   
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
	
context Operation
   
def : _appliesFilter_Operation(arguments : OrderedSet(OCLExpression)) : Boolean =
   ownedParameters->size() = arguments->size() and arguments->forAll(x | let argIdx  = arguments->indexOf(x)
   in x.type.conformsTo(ownedParameters->at(argIdx).type)
   )
context Visitable
-- Operation unqualified lookup
def : _lookupOperation(env : lookup::LookupEnvironment, oName : String, arguments : OrderedSet(OCLExpression)) : OrderedSet(Operation) =
let foundOperation = env.namedElements->selectByKind(Operation)->select(name = oName)
                                         ->select(_appliesFilter_Operation(arguments))
in  if foundOperation->isEmpty() and not (env.parentEnv = null)
   then _lookupOperation(env.parentEnv, oName, arguments)
   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, arguments : OrderedSet(OCLExpression)) : Operation[?] =
let foundOperation = _lookupOperation(unqualified_env_Operation(), oName, arguments)
in  if foundOperation->isEmpty()
   then null
   else foundOperation->first() -- LookupVisitor will report ambiguous result
   endif
   
def : lookupOperation(oName : String, arguments : OrderedSet(OCLExpression)) : Operation[?] =
   _lookupUnqualifiedOperation(oName, arguments)
def : lookupOperation(aPathElementCS : cs::PathElementCS, arguments : OrderedSet(OCLExpression)) : Operation[?] =
   _lookupUnqualifiedOperation(aPathElementCS.elementName, arguments)
-- End of Operation unqualified lookup 
   
-- Operation qualified-name lookup
def : lookupOperation(aPathNameCS : cs::PathNameCS, arguments : OrderedSet(OCLExpression)) : Operation[?] =
   lookupOperation(aPathNameCS .pathElements, arguments)
   
def : lookupOperation(segments : OrderedSet(cs::PathElementCS), arguments : OrderedSet(OCLExpression)) : Operation[?] =
   if segments->size() = 1
   then lookupOperation(segments->first(), arguments)
   else let qualifierSegments = segments->subOrderedSet(1,segments->size()-1),
            qualifier = lookupClass(qualifierSegments)
        in qualifier?.lookupQualifiedOperation(segments->last(), arguments)
   endif
context Visitable
-- Property unqualified lookup
def : _lookupProperty(env : lookup::LookupEnvironment, pName : String) : OrderedSet(Property) =
let foundProperty = env.namedElements->selectByKind(Property)->select(name = pName)
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(pName : String) : Property[?] =
   _lookupUnqualifiedProperty(pName)
def : lookupProperty(aPathElementCS : cs::PathElementCS) : Property[?] =
   _lookupUnqualifiedProperty(aPathElementCS.elementName)
-- End of Property unqualified lookup 
   
-- Property qualified-name lookup
def : lookupProperty(aPathNameCS : cs::PathNameCS) : Property[?] =
   lookupProperty(aPathNameCS .pathElements)
   
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
context Visitable
-- Variable unqualified lookup
def : _lookupVariable(env : lookup::LookupEnvironment, vName : String) : OrderedSet(Variable) =
let foundVariable = env.namedElements->selectByKind(Variable)->select(name = vName)
in  if foundVariable->isEmpty() and not (env.parentEnv = null)
   then _lookupVariable(env.parentEnv, vName)
   else foundVariable
   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 : _lookupUnqualifiedVariable(vName : String) : Variable[?] =
let foundVariable = _lookupVariable(unqualified_env_Variable(), vName)
in  if foundVariable->isEmpty()
   then null
   else foundVariable->first() -- LookupVisitor will report ambiguous result
   endif
   
def : lookupVariable(vName : String) : Variable[?] =
   _lookupUnqualifiedVariable(vName)
def : lookupVariable(aPathElementCS : cs::PathElementCS) : Variable[?] =
   _lookupUnqualifiedVariable(aPathElementCS.elementName)
-- End of Variable unqualified lookup 
   
context Root
def : _unqualified_env_Package(child : ocl::OclElement) : lookup::LookupEnvironment =
   parentEnv_Package()
      .addElements(ownedPackages)
      --TODO .addElements(ownedImports._exported_env(self).namedElements)
      
context Package
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 : _unqualified_env_Operation(child : ocl::OclElement) : lookup::LookupEnvironment =
   let allSuperClasses = self->closure(superClasses)
   in 
   parentEnv_Operation().nestedEnv()
      .addElements(allSuperClasses.ownedOperations)
      .nestedEnv()
      .addElements(ownedOperations)
      
def : _unqualified_env_Property(child : ocl::OclElement) : lookup::LookupEnvironment =
   let allSuperClasses = self->closure(superClasses)
   in 
   parentEnv_Property().nestedEnv()
      .addElements(allSuperClasses.ownedProperties)
      .nestedEnv()
      .addElements(ownedProperties)
      
def : _exported_env_Operation(importer : ocl::OclElement) : lookup::LookupEnvironment =
   let allSuperClasses = self->closure(superClasses)
   in 
   let env = lookup::LookupEnvironment {}
   in env
      .addElements(allSuperClasses.ownedOperations)
      .nestedEnv()
      .addElements(ownedOperations)
   
def : _exported_env_Property(importer : ocl::OclElement) : lookup::LookupEnvironment =
   let allSuperClasses = self->closure(superClasses)
   in 
   let env = lookup::LookupEnvironment {}
   in env
      .addElements(allSuperClasses.ownedOperations)
      .nestedEnv()
      .addElements(ownedProperties)
   
   
def : _lookupExportedOperation(importer : ocl::OclElement, oName : String, arguments : OrderedSet(OCLExpression)) : Operation[?] =
   let foundOperation = _lookupOperation(_exported_env_Operation(importer), oName, arguments)
   in  if foundOperation->isEmpty()
      then null
      else foundOperation->first()
      endif
def : lookupExportedOperation(importer : ocl::OclElement, oName : String, arguments : OrderedSet(OCLExpression)) : Operation[?] =
   _lookupExportedOperation(importer, oName, arguments)
def : lookupExportedOperation(importer : ocl::OclElement, aPathElementCS : cs::PathElementCS, arguments : OrderedSet(OCLExpression)) : Operation[?] =
   _lookupExportedOperation(importer, aPathElementCS.elementName, arguments)

   
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, pName : String) : Property[?] =
   _lookupExportedProperty(importer, pName)
def : lookupExportedProperty(importer : ocl::OclElement, aPathElementCS : cs::PathElementCS) : Property[?] =
   _lookupExportedProperty(importer, aPathElementCS.elementName)

context Visitable
-- Class exports Operation
def : lookupOperationFrom(exporter : Class , cName : String, arguments : OrderedSet(OCLExpression)) : Operation[?] =
   exporter.lookupExportedOperation(self, cName, arguments)
def : lookupOperationFrom(exporter : Class, aPathElementCS : cs::PathElementCS, arguments : OrderedSet(OCLExpression)) : Operation[?] =
   exporter.lookupExportedOperation(self, aPathElementCS, arguments)
def : lookupOperationFrom(exporter : Class, aPathNameCS : cs::PathNameCS, arguments : OrderedSet(OCLExpression)) : Operation[?] =
   lookupOperationFrom(exporter, aPathNameCS.pathElements, arguments)

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

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
context Operation
def : _unqualified_env_Variable(child : ocl::OclElement) : lookup::LookupEnvironment =
   parentEnv_Variable().nestedEnv()
      .addElements(ownedParameters)
      
context ExpressionInOCL
def : _unqualified_env_Variable(child : ocl::OclElement) : lookup::LookupEnvironment =
   parentEnv_Variable().nestedEnv()
      .addElements(ownedSelfVar)
      
context LetExp
def : _unqualified_env_Variable(child : ocl::OclElement) : lookup::LookupEnvironment =
   if not (ownedVariable->includes(child)
      )
   then parentEnv_Variable().nestedEnv()
      .addElements(ownedVariable)
      
   else parentEnv_Variable()
   endif

endpackage

Back to the top