1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2008 Jean Privat <jean@pryen.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Collect things from a `Model`.
21 # `model_collect` offers a flattened view of the model without considering any
23 # For this reason, `model_collect` lists all the definitions reachable from all
26 # This is usefull for tools that need a global view of a model like `nitdoc`,
28 # It shoul not be used for compiling stuffs like computing VFT, where the listed
29 # entities could not be reachable depending on the modules really imported.
36 # Collect mclassdefs introduced in `self` with `visibility >= to min_visibility`.
37 fun collect_intro_mclassdefs
(min_visibility
: MVisibility): Set[MClassDef] do
38 var res
= new HashSet[MClassDef]
39 for mclassdef
in mclassdefs
do
40 if not mclassdef
.is_intro
then continue
41 if mclassdef
.mclass
.visibility
< min_visibility
then continue
47 # Collect mclassdefs redefined in `self` with `visibility >= to min_visibility`.
48 fun collect_redef_mclassdefs
(min_visibility
: MVisibility): Set[MClassDef] do
49 var res
= new HashSet[MClassDef]
50 for mclassdef
in mclassdefs
do
51 if mclassdef
.is_intro
then continue
52 if mclassdef
.mclass
.visibility
< min_visibility
then continue
58 # Collect mclasses introduced in `self` with `visibility >= to min_visibility`.
59 fun collect_intro_mclasses
(min_visibility
: MVisibility): Set[MClass] do
60 var res
= new HashSet[MClass]
61 for mclass
in intro_mclasses
do
62 if mclass
.visibility
< min_visibility
then continue
68 # Collect mclasses redefined in `self` with `visibility >= to min_visibility`.
69 fun collect_redef_mclasses
(min_visibility
: MVisibility): Set[MClass] do
70 var mclasses
= new HashSet[MClass]
71 for c
in mclassdefs
do
72 if c
.mclass
.visibility
< min_visibility
then continue
73 if not c
.is_intro
then mclasses
.add
(c
.mclass
)
81 # Collect direct parents of `self` with `visibility >= to min_visibility`.
82 fun collect_parents
(min_visibility
: MVisibility): Set[MClass] do
83 var res
= new HashSet[MClass]
84 for mclassdef
in mclassdefs
do
85 for mclasstype
in mclassdef
.supertypes
do
86 var mclass
= mclasstype
.mclass
87 if mclass
.visibility
< min_visibility
then continue
94 # Collect all ancestors of `self` with `visibility >= to min_visibility`.
95 fun collect_ancestors
(min_visibility
: MVisibility): Set[MClass] do
96 var res
= new HashSet[MClass]
97 for mclassdef
in self.mclassdefs
do
98 for super_mclassdef
in mclassdef
.in_hierarchy
.greaters
do
99 if super_mclassdef
== mclassdef
then continue # skip self
100 var mclass
= super_mclassdef
.mclass
101 if mclass
.visibility
< min_visibility
then continue
108 # Collect direct children of `self` with `visibility >= to min_visibility`.
109 fun collect_children
(min_visibility
: MVisibility): Set[MClass] do
110 var res
= new HashSet[MClass]
111 for mclassdef
in self.mclassdefs
do
112 for sub_mclassdef
in mclassdef
.in_hierarchy
.direct_smallers
do
113 if sub_mclassdef
== mclassdef
then continue # skip self
114 var mclass
= sub_mclassdef
.mclass
115 if mclass
.visibility
< min_visibility
then continue
122 # Collect all descendants of `self` with `visibility >= to min_visibility`.
123 fun descendants
(min_visibility
: MVisibility): Set[MClass] do
124 var res
= new HashSet[MClass]
125 for mclassdef
in self.mclassdefs
do
126 for sub_mclassdef
in mclassdef
.in_hierarchy
.smallers
do
127 if sub_mclassdef
== mclassdef
then continue # skip self
128 var mclass
= sub_mclassdef
.mclass
129 if mclass
.visibility
< min_visibility
then continue
136 # Collect all mproperties introduced in 'self' with `visibility >= min_visibility`.
137 fun collect_intro_mproperties
(min_visibility
: MVisibility): Set[MProperty] do
138 var set
= new HashSet[MProperty]
139 for mclassdef
in mclassdefs
do
140 for mprop
in mclassdef
.intro_mproperties
do
141 if mprop
.visibility
< min_visibility
then continue
148 # Collect all mproperties redefined in 'self' with `visibility >= min_visibility`.
149 fun collect_redef_mproperties
(min_visibility
: MVisibility): Set[MProperty] do
150 var set
= new HashSet[MProperty]
151 for mclassdef
in mclassdefs
do
152 for mpropdef
in mclassdef
.mpropdefs
do
153 if mpropdef
.mproperty
.visibility
< min_visibility
then continue
154 if mpropdef
.mproperty
.intro_mclassdef
.mclass
!= self then set
.add
(mpropdef
.mproperty
)
160 # Collect mproperties introduced and redefined in 'self' with `visibility >= min_visibility`.
161 fun collect_local_mproperties
(min_visibility
: MVisibility): Set[MProperty] do
162 var set
= new HashSet[MProperty]
163 set
.add_all collect_intro_mproperties
(min_visibility
)
164 set
.add_all collect_redef_mproperties
(min_visibility
)
168 # Collect all mproperties inehrited by 'self' with `visibility >= min_visibility`.
169 fun collect_inherited_mproperties
(min_visibility
: MVisibility): Set[MProperty] do
170 var set
= new HashSet[MProperty]
171 for parent
in collect_parents
(min_visibility
) do
172 set
.add_all
(parent
.collect_intro_mproperties
(min_visibility
))
173 set
.add_all
(parent
.collect_inherited_mproperties
(min_visibility
))
178 # Collect all mproperties accessible by 'self' with `visibility >= min_visibility`.
180 # This include introduced, redefined, inherited mproperties.
181 fun collect_accessible_mproperties
(min_visibility
: MVisibility): Set[MProperty] do
182 var set
= new HashSet[MProperty]
183 set
.add_all
(collect_intro_mproperties
(min_visibility
))
184 set
.add_all
(collect_redef_mproperties
(min_visibility
))
185 set
.add_all
(collect_inherited_mproperties
(min_visibility
))
189 # Collect mmethods introduced in 'self' with `visibility >= min_visibility`.
190 fun collect_intro_mmethods
(min_visibility
: MVisibility): Set[MMethod] do
191 var res
= new HashSet[MMethod]
192 for mproperty
in collect_intro_mproperties
(min_visibility
) do
193 if mproperty
isa MMethod then res
.add
(mproperty
)
198 # Collect mmethods redefined in 'self' with `visibility >= min_visibility`.
199 fun collect_redef_mmethods
(min_visibility
: MVisibility): Set[MMethod] do
200 var res
= new HashSet[MMethod]
201 for mproperty
in collect_redef_mproperties
(min_visibility
) do
202 if mproperty
isa MMethod then res
.add
(mproperty
)
207 # Collect mmethods introduced and redefined in 'self' with `visibility >= min_visibility`.
208 fun collect_local_mmethods
(min_visibility
: MVisibility): Set[MMethod] do
209 var set
= new HashSet[MMethod]
210 set
.add_all collect_intro_mmethods
(min_visibility
)
211 set
.add_all collect_redef_mmethods
(min_visibility
)
215 # Collect mattributes introduced in 'self' with `visibility >= min_visibility`.
216 fun collect_intro_mattributes
(min_visibility
: MVisibility): Set[MAttribute] do
217 var res
= new HashSet[MAttribute]
218 for mproperty
in collect_intro_mproperties
(min_visibility
) do
219 if mproperty
isa MAttribute then res
.add
(mproperty
)
224 # Collect mattributes redefined in 'self' with `visibility >= min_visibility`.
225 fun collect_redef_mattributes
(min_visibility
: MVisibility): Set[MAttribute] do
226 var res
= new HashSet[MAttribute]
227 for mproperty
in collect_redef_mproperties
(min_visibility
) do
228 if mproperty
isa MAttribute then res
.add
(mproperty
)
233 # Collect mattributes introduced and redefined in 'self' with `visibility >= min_visibility`.
234 fun collect_local_mattributes
(min_visibility
: MVisibility): Set[MAttribute] do
235 var set
= new HashSet[MAttribute]
236 set
.add_all collect_intro_mattributes
(min_visibility
)
237 set
.add_all collect_redef_mattributes
(min_visibility
)
241 # Collect mattributes inherited by 'self' with `visibility >= min_visibility`.
242 fun collect_inherited_mattributes
(min_visibility
: MVisibility): Set[MAttribute] do
243 var res
= new HashSet[MAttribute]
244 for mproperty
in collect_inherited_mproperties
(min_visibility
) do
245 if mproperty
isa MAttribute then res
.add
(mproperty
)
250 # Collect all mattributes accessible by 'self' with `visibility >= min_visibility`.
252 # This include introduced, redefined, inherited mattributes.
253 fun collect_accessible_mattributes
(min_visibility
: MVisibility): Set[MAttribute] do
254 var set
= new HashSet[MAttribute]
255 set
.add_all
(collect_intro_mattributes
(min_visibility
))
256 set
.add_all
(collect_redef_mattributes
(min_visibility
))
257 set
.add_all
(collect_inherited_mattributes
(min_visibility
))
262 redef class MClassDef
263 # Collect mpropdefs in 'self' with `visibility >= min_visibility`.
264 fun collect_mpropdefs
(min_visibility
: MVisibility): Set[MPropDef] do
265 var res
= new HashSet[MPropDef]
266 for mpropdef
in mpropdefs
do
267 if mpropdef
.mproperty
.visibility
< min_visibility
then continue
273 # Collect mpropdefs introduced in 'self' with `visibility >= min_visibility`.
274 fun collect_intro_mpropdefs
(min_visibility
: MVisibility): Set[MPropDef] do
275 var res
= new HashSet[MPropDef]
276 for mpropdef
in mpropdefs
do
277 if not mpropdef
.is_intro
then continue
278 if mpropdef
.mproperty
.visibility
< min_visibility
then continue
284 # Collect mpropdefs redefined in 'self' with `visibility >= min_visibility`.
285 fun collect_redef_mpropdefs
(min_visibility
: MVisibility): Set[MPropDef] do
286 var res
= new HashSet[MPropDef]
287 for mpropdef
in mpropdefs
do
288 if mpropdef
.is_intro
then continue
289 if mpropdef
.mproperty
.visibility
< min_visibility
then continue
295 # Collect modifiers like redef, private etc.
296 fun collect_modifiers
: Array[String] do
297 var res
= new Array[String]
301 res
.add mclass
.visibility
.to_s
303 res
.add mclass
.kind
.to_s
309 # Collect modifiers like redef, private, abstract, intern, fun etc.
310 fun collect_modifiers
: Array[String] do
311 var res
= new Array[String]
315 res
.add mproperty
.visibility
.to_s
318 if mprop
isa MVirtualTypeDef then
320 else if mprop
isa MMethodDef then
321 if mprop
.is_abstract
then
323 else if mprop
.is_intern
then
326 if mprop
.mproperty
.is_init
then