Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4a1166059f86f28b517c7e93e348b03c3b7281ab (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
import  cs : 'ClassesCS.ecore#/'
import  as : 'Classes.ecore#/'
import 'EnvExample2.ecore'

package ocl
---- Default Environment related functionality
context OclElement
--	
def : _exported_env(importer : OclElement) : lookup::LookupEnvironment[1] =
	lookup::LookupEnvironment { }
	
-- 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_Class(child : OclElement) : lookup::LookupEnvironment[1] =
	parentEnv_Class()
def : _unqualified_env_Package(child : OclElement) : lookup::LookupEnvironment[1] =
	parentEnv_Package()

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
-- End of domain specific default functionality
endpackage 

package lookup
context LookupEnvironment
def : nestedEnv() : LookupEnvironment[1] = 
	LookupEnvironment {
		parentEnv = self
	}
endpackage

package as

	
context Root
def : _unqualified_env_Package(child : ocl::OclElement) : lookup::LookupEnvironment =
	parentEnv_Package()
		.addElements(ownedPackages)
		
context Package
	
def : _lookupQualifiedPackage(pName : String) : Package[?] =
	let foundPackage = _lookupPackage(_qualified_env(), pName)
	in  if foundPackage->isEmpty()
		then null
		else foundPackage->first()
		endif
def : lookupQualifiedPackage(aPathElementCS : cs::PathElementCS) : Package[?] =
   _lookupQualifiedPackage(aPathElementCS.name)
   
	
def : _lookupQualifiedClass(cName : String) : Class[?] =
	let foundClass = _lookupClass(_qualified_env(), cName)
	in  if foundClass->isEmpty()
		then null
		else foundClass->first()
		endif
def : lookupQualifiedClass(aPathElementCS : cs::PathElementCS) : Class[?] =
   _lookupQualifiedClass(aPathElementCS.name)
   
	
def : _qualified_env() : lookup::LookupEnvironment =
	let env = lookup::LookupEnvironment{}
	in env
		.addElements(ownedPackages)
.addElements(ownedClasses)
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 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



endpackage

Back to the top