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 modifier keywords like `redef`, `private` etc.
37 fun collect_modifiers
: Array[String] do
38 return new Array[String]
43 redef fun collect_modifiers
do
51 redef fun collect_modifiers
do
60 redef fun collect_modifiers
do
66 # Collect all transitive imports.
67 fun collect_ancestors
(view
: ModelView): Set[MModule] do
68 var res
= new HashSet[MModule]
69 for mentity
in in_importation
.greaters
do
70 if mentity
== self then continue
71 if not view
.accept_mentity
(mentity
) then continue
77 # Collect direct imports.
78 fun collect_parents
(view
: ModelView): Set[MModule] do
79 var res
= new HashSet[MModule]
80 for mentity
in in_importation
.direct_greaters
do
81 if mentity
== self then continue
82 if not view
.accept_mentity
(mentity
) then continue
88 # Collect direct children (modules that directly import `self`).
89 fun collect_children
(view
: ModelView): Set[MModule] do
90 var res
= new HashSet[MModule]
91 for mentity
in in_importation
.direct_smallers
do
92 if mentity
== self then continue
93 if not view
.accept_mentity
(mentity
) then continue
99 # Collect all transitive children.
100 fun collect_descendants
(view
: ModelView): Set[MModule] do
101 var res
= new HashSet[MModule]
102 for mentity
in in_importation
.smallers
do
103 if mentity
== self then continue
104 if not view
.accept_mentity
(mentity
) then continue
110 # Build the importation poset for `self`
111 fun importation_poset
(view
: ModelView): POSet[MModule] do
112 var mmodules
= new HashSet[MModule]
114 mmodules
.add_all collect_ancestors
(view
)
115 mmodules
.add_all collect_parents
(view
)
116 mmodules
.add_all collect_children
(view
)
117 mmodules
.add_all collect_descendants
(view
)
118 return view
.mmodules_poset
(mmodules
)
121 # Collect mclassdefs introduced in `self` with `visibility >= to min_visibility`.
122 fun collect_intro_mclassdefs
(view
: ModelView): Set[MClassDef] do
123 var res
= new HashSet[MClassDef]
124 for mclassdef
in mclassdefs
do
125 if not mclassdef
.is_intro
then continue
126 if not view
.accept_mentity
(mclassdef
) then continue
132 # Collect mclassdefs redefined in `self` with `visibility >= to min_visibility`.
133 fun collect_redef_mclassdefs
(view
: ModelView): Set[MClassDef] do
134 var res
= new HashSet[MClassDef]
135 for mclassdef
in mclassdefs
do
136 if mclassdef
.is_intro
then continue
137 if not view
.accept_mentity
(mclassdef
) then continue
143 # Collect mclasses introduced in `self` with `visibility >= to min_visibility`.
144 fun collect_intro_mclasses
(view
: ModelView): Set[MClass] do
145 var res
= new HashSet[MClass]
146 for mclass
in intro_mclasses
do
147 if not view
.accept_mentity
(mclass
) then continue
153 # Collect mclasses redefined in `self` with `visibility >= to min_visibility`.
154 fun collect_redef_mclasses
(view
: ModelView): Set[MClass] do
155 var mclasses
= new HashSet[MClass]
156 for mclassdef
in mclassdefs
do
157 if not view
.accept_mentity
(mclassdef
) then continue
158 if not mclassdef
.is_intro
then mclasses
.add
(mclassdef
.mclass
)
166 redef fun collect_modifiers
do return intro
.collect_modifiers
168 # Collect direct parents of `self` with `visibility >= to min_visibility`.
169 fun collect_parents
(view
: ModelView): Set[MClass] do
170 var res
= new HashSet[MClass]
171 for mclassdef
in mclassdefs
do
172 for mclasstype
in mclassdef
.supertypes
do
173 var mclass
= mclasstype
.mclass
174 if not view
.accept_mentity
(mclass
) then continue
181 # Collect all ancestors of `self` with `visibility >= to min_visibility`.
182 fun collect_ancestors
(view
: ModelView): Set[MClass] do
183 var res
= new HashSet[MClass]
184 for mclassdef
in self.mclassdefs
do
185 for super_mclassdef
in mclassdef
.in_hierarchy
.greaters
do
186 if super_mclassdef
== mclassdef
then continue # skip self
187 var mclass
= super_mclassdef
.mclass
188 if not view
.accept_mentity
(mclass
) then continue
195 # Collect direct children of `self` with `visibility >= to min_visibility`.
196 fun collect_children
(view
: ModelView): Set[MClass] do
197 var res
= new HashSet[MClass]
198 for mclassdef
in self.mclassdefs
do
199 for sub_mclassdef
in mclassdef
.in_hierarchy
.direct_smallers
do
200 if sub_mclassdef
== mclassdef
then continue # skip self
201 var mclass
= sub_mclassdef
.mclass
202 if not view
.accept_mentity
(mclass
) then continue
209 # Collect all descendants of `self` with `visibility >= to min_visibility`.
210 fun collect_descendants
(view
: ModelView): Set[MClass] do
211 var res
= new HashSet[MClass]
212 for mclassdef
in self.mclassdefs
do
213 for sub_mclassdef
in mclassdef
.in_hierarchy
.smallers
do
214 if sub_mclassdef
== mclassdef
then continue # skip self
215 var mclass
= sub_mclassdef
.mclass
216 if not view
.accept_mentity
(mclass
) then continue
223 # Collect all mproperties introduced in 'self' with `visibility >= min_visibility`.
224 fun collect_intro_mproperties
(view
: ModelView): Set[MProperty] do
225 var set
= new HashSet[MProperty]
226 for mclassdef
in mclassdefs
do
227 for mprop
in mclassdef
.intro_mproperties
do
228 if not view
.accept_mentity
(mprop
) then continue
235 # Collect all mproperties redefined in 'self' with `visibility >= min_visibility`.
236 fun collect_redef_mproperties
(view
: ModelView): Set[MProperty] do
237 var set
= new HashSet[MProperty]
238 for mclassdef
in mclassdefs
do
239 for mpropdef
in mclassdef
.mpropdefs
do
240 if mpropdef
.mproperty
.intro_mclassdef
.mclass
== self then continue
241 if not view
.accept_mentity
(mpropdef
) then continue
242 set
.add
(mpropdef
.mproperty
)
248 # Collect mproperties introduced and redefined in 'self' with `visibility >= min_visibility`.
249 fun collect_local_mproperties
(view
: ModelView): Set[MProperty] do
250 var set
= new HashSet[MProperty]
251 set
.add_all collect_intro_mproperties
(view
)
252 set
.add_all collect_redef_mproperties
(view
)
256 # Collect all mproperties inehrited by 'self' with `visibility >= min_visibility`.
257 fun collect_inherited_mproperties
(view
: ModelView): Set[MProperty] do
258 var set
= new HashSet[MProperty]
259 for parent
in collect_parents
(view
) do
260 set
.add_all
(parent
.collect_intro_mproperties
(view
))
261 set
.add_all
(parent
.collect_inherited_mproperties
(view
))
266 # Collect all mproperties accessible by 'self' with `visibility >= min_visibility`.
268 # This include introduced, redefined, inherited mproperties.
269 fun collect_accessible_mproperties
(view
: ModelView): Set[MProperty] do
270 var set
= new HashSet[MProperty]
271 set
.add_all
(collect_intro_mproperties
(view
))
272 set
.add_all
(collect_redef_mproperties
(view
))
273 set
.add_all
(collect_inherited_mproperties
(view
))
277 # Collect mmethods introduced in 'self' with `visibility >= min_visibility`.
278 fun collect_intro_mmethods
(view
: ModelView): Set[MMethod] do
279 var res
= new HashSet[MMethod]
280 for mproperty
in collect_intro_mproperties
(view
) do
281 if mproperty
isa MMethod then res
.add
(mproperty
)
286 # Collect mmethods redefined in 'self' with `visibility >= min_visibility`.
287 fun collect_redef_mmethods
(view
: ModelView): Set[MMethod] do
288 var res
= new HashSet[MMethod]
289 for mproperty
in collect_redef_mproperties
(view
) do
290 if mproperty
isa MMethod then res
.add
(mproperty
)
295 # Collect mmethods introduced and redefined in 'self' with `visibility >= min_visibility`.
296 fun collect_local_mmethods
(view
: ModelView): Set[MMethod] do
297 var set
= new HashSet[MMethod]
298 set
.add_all collect_intro_mmethods
(view
)
299 set
.add_all collect_redef_mmethods
(view
)
303 # Collect mmethods inherited by 'self' if accepted by `view`.
304 fun collect_inherited_mmethods
(view
: ModelView): Set[MMethod] do
305 var res
= new HashSet[MMethod]
306 for mproperty
in collect_inherited_mproperties
(view
) do
307 if mproperty
isa MMethod then res
.add
(mproperty
)
312 # Collect mattributes introduced in 'self' with `visibility >= min_visibility`.
313 fun collect_intro_mattributes
(view
: ModelView): Set[MAttribute] do
314 var res
= new HashSet[MAttribute]
315 for mproperty
in collect_intro_mproperties
(view
) do
316 if mproperty
isa MAttribute then res
.add
(mproperty
)
321 # Collect mattributes redefined in 'self' with `visibility >= min_visibility`.
322 fun collect_redef_mattributes
(view
: ModelView): Set[MAttribute] do
323 var res
= new HashSet[MAttribute]
324 for mproperty
in collect_redef_mproperties
(view
) do
325 if mproperty
isa MAttribute then res
.add
(mproperty
)
330 # Collect mattributes introduced and redefined in 'self' with `visibility >= min_visibility`.
331 fun collect_local_mattributes
(view
: ModelView): Set[MAttribute] do
332 var set
= new HashSet[MAttribute]
333 set
.add_all collect_intro_mattributes
(view
)
334 set
.add_all collect_redef_mattributes
(view
)
338 # Collect mattributes inherited by 'self' with `visibility >= min_visibility`.
339 fun collect_inherited_mattributes
(view
: ModelView): Set[MAttribute] do
340 var res
= new HashSet[MAttribute]
341 for mproperty
in collect_inherited_mproperties
(view
) do
342 if mproperty
isa MAttribute then res
.add
(mproperty
)
347 # Collect all mattributes accessible by 'self' with `visibility >= min_visibility`.
349 # This include introduced, redefined, inherited mattributes.
350 fun collect_accessible_mattributes
(view
: ModelView): Set[MAttribute] do
351 var set
= new HashSet[MAttribute]
352 set
.add_all
(collect_intro_mattributes
(view
))
353 set
.add_all
(collect_redef_mattributes
(view
))
354 set
.add_all
(collect_inherited_mattributes
(view
))
358 # Collect init mmethods introduced in 'self' if accepted by `view`.
359 fun collect_intro_inits
(view
: ModelView): Set[MMethod] do
360 var res
= new HashSet[MMethod]
361 for mproperty
in collect_intro_mmethods
(view
) do
362 if mproperty
.is_init
then res
.add
(mproperty
)
367 # Collect init mmethods redefined in 'self' if accepted by `view`.
368 fun collect_redef_inits
(view
: ModelView): Set[MMethod] do
369 var res
= new HashSet[MMethod]
370 for mproperty
in collect_redef_mmethods
(view
) do
371 if mproperty
.is_init
then res
.add
(mproperty
)
376 # Collect init mmethods introduced and redefined in 'self' if accepted by `view`.
377 fun collect_local_inits
(view
: ModelView): Set[MMethod] do
378 var set
= new HashSet[MMethod]
379 set
.add_all collect_intro_inits
(view
)
380 set
.add_all collect_redef_inits
(view
)
384 # Collect init mmethods inherited by 'self' if accepted by `view`.
385 fun collect_inherited_inits
(view
: ModelView): Set[MMethod] do
386 var res
= new HashSet[MMethod]
387 for mproperty
in collect_inherited_mmethods
(view
) do
388 if mproperty
.is_init
then res
.add
(mproperty
)
393 # Collect all init mmethods accessible by 'self' if accepted by `view`.
395 # This include introduced, redefined, inherited inits.
396 fun collect_accessible_inits
(view
: ModelView): Set[MMethod] do
397 var set
= new HashSet[MMethod]
398 set
.add_all
(collect_intro_inits
(view
))
399 set
.add_all
(collect_redef_inits
(view
))
400 set
.add_all
(collect_inherited_inits
(view
))
405 redef class MClassDef
407 # Collect mpropdefs in 'self' with `visibility >= min_visibility`.
408 fun collect_mpropdefs
(view
: ModelView): Set[MPropDef] do
409 var res
= new HashSet[MPropDef]
410 for mpropdef
in mpropdefs
do
411 if not view
.accept_mentity
(mpropdef
) then continue
417 # Collect mpropdefs introduced in 'self' with `visibility >= min_visibility`.
418 fun collect_intro_mpropdefs
(view
: ModelView): Set[MPropDef] do
419 var res
= new HashSet[MPropDef]
420 for mpropdef
in mpropdefs
do
421 if not mpropdef
.is_intro
then continue
422 if not view
.accept_mentity
(mpropdef
) then continue
428 # Collect mpropdefs redefined in 'self' with `visibility >= min_visibility`.
429 fun collect_redef_mpropdefs
(view
: ModelView): Set[MPropDef] do
430 var res
= new HashSet[MPropDef]
431 for mpropdef
in mpropdefs
do
432 if mpropdef
.is_intro
then continue
433 if not view
.accept_mentity
(mpropdef
) then continue
439 redef fun collect_modifiers
do
444 res
.add mclass
.visibility
.to_s
446 res
.add mclass
.kind
.to_s
451 redef class MProperty
452 redef fun collect_modifiers
do return intro
.collect_modifiers
456 redef fun collect_modifiers
do
461 res
.add mproperty
.visibility
.to_s
464 if mprop
isa MVirtualTypeDef then
466 else if mprop
isa MMethodDef then
467 if mprop
.is_abstract
then
469 else if mprop
.is_intern
then
472 if mprop
.mproperty
.is_init
then
477 else if mprop
isa MAttributeDef then