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 `ModelView`
19 # This module introduce several usefull methods to list and count things from a
22 # First setup you view from a Model:
25 # var view = new ModelView(model, mainmodule)
28 # Then ask question using the view:
31 # print number of parents for `{my_class}`
32 # print my_class.collect_parents(view).count
37 # `model_collect` offers a flattened view of the model without considering any
39 # For this reason, `model_collect` lists all the definitions reachable from all
42 # This is usefull for tools that need a global view of a model like `nitdoc`,
43 # `nitx`, `nitmetrics` or `nituml`.
44 # It should not be used for compiling stuffs like computing VFT, where the listed
45 # entities could not be reachable depending on the modules really imported.
52 # FIXME used to bypass RTA limitation on type resolution
55 # Collect modifier keywords like `redef`, `private` etc
56 fun collect_modifiers
: Array[String] do return new Array[String]
58 # Collect `self` linearization anchored on `mainmodule`
59 fun collect_linearization
(mainmodule
: MModule): nullable Array[MEntity] do
63 # Collect `self` ancestors (direct and indirect)
65 # The concept of ancestor is abstract at this stage.
66 fun collect_ancestors
(view
: ModelView): Set[MENTITY] do
67 var done
= new HashSet[MENTITY]
68 var todo
= new Array[MENTITY]
70 todo
.add_all collect_parents
(view
)
71 while todo
.not_empty
do
72 var mentity
= todo
.pop
73 if mentity
== self or done
.has
(mentity
) then continue
75 todo
.add_all mentity
.collect_parents
(view
)
80 # Collect `self` parents (direct ancestors)
82 # The concept of parent is abstract at this stage.
83 fun collect_parents
(view
: ModelView): Set[MENTITY] is abstract
85 # Collect `self` children (direct descendants)
87 # The concept of child is abstract at this stage.
88 fun collect_children
(view
: ModelView): Set[MENTITY] is abstract
90 # Collect `self` descendants (direct and direct)
92 # The concept of descendant is abstract at this stage.
93 fun collect_descendants
(view
: ModelView): Set[MENTITY] do
94 var done
= new HashSet[MENTITY]
95 var todo
= new Array[MENTITY]
97 todo
.add_all collect_children
(view
)
98 while todo
.not_empty
do
99 var mentity
= todo
.pop
100 if mentity
== self or done
.has
(mentity
) then continue
102 todo
.add_all mentity
.collect_children
(view
)
107 # Build a poset representing `self` in it's own hierarchy
109 # The notion of hierarchy depends on the type of MEntity.
112 # * `MPackage`: package dependencies
113 # * `MGroup`: group dependencies
114 # * `MModule`: modules imports
115 # * `MClass`: class inheritance (all classdefs flattened)
116 # * `MClassDef`: classdef inheritance
117 # * `MProperty`: property definitions graph (all propdefs flattened)
118 # * `MPropDef`: property definitions graph
119 fun hierarchy_poset
(view
: ModelView): POSet[MENTITY] do
120 var poset
= new POSet[MENTITY]
121 var parents_done
= new HashSet[MENTITY]
122 var parents
= new Array[MENTITY]
124 while parents
.not_empty
do
125 var mentity
= parents
.pop
126 if parents_done
.has
(mentity
) then continue
127 parents_done
.add mentity
128 poset
.add_node mentity
129 for parent
in mentity
.collect_parents
(view
) do
130 poset
.add_edge
(mentity
, parent
)
134 var children_done
= new HashSet[MEntity]
135 var children
= new Array[MEntity]
137 while children
.not_empty
do
138 var mentity
= children
.pop
139 if children_done
.has
(mentity
) then continue
140 children_done
.add mentity
141 for child
in mentity
.collect_children
(view
) do
142 poset
.add_edge
(child
, mentity
)
152 # Collect all MPackages in `self`
153 fun collect_mpackages
(view
: ModelView): HashSet[MPackage] do
154 var res
= new HashSet[MPackage]
155 for mpackage
in mpackages
do
156 if not view
.accept_mentity
(mpackage
) then continue
162 # Collect all MModules in `self`
163 fun collect_mmodules
(view
: ModelView): HashSet[MModule] do
164 var res
= new HashSet[MModule]
165 for mpackage
in collect_mpackages
(view
) do
166 res
.add_all mpackage
.collect_all_mmodules
(view
)
171 # Collect all MClasses introduced in `self`
172 fun collect_intro_mclasses
(view
: ModelView): HashSet[MClass] do
173 var res
= new HashSet[MClass]
174 for mpackage
in collect_mpackages
(view
) do
175 res
.add_all mpackage
.collect_intro_mclasses
(view
)
180 # Collect all MProperties introduced in `self`
181 fun collect_intro_mproperties
(view
: ModelView): HashSet[MProperty] do
182 var res
= new HashSet[MProperty]
183 for mpackage
in collect_mpackages
(view
) do
184 res
.add_all mpackage
.collect_intro_mproperties
(view
)
192 redef fun collect_modifiers
do return super + ["package"]
194 # Collect all packages directly imported by `self`
195 redef fun collect_parents
(view
) do
196 var res
= new HashSet[MENTITY]
197 for mgroup
in mgroups
do
198 for parent
in mgroup
.collect_parents
(view
) do
199 var mpackage
= parent
.mpackage
200 if mpackage
== self or not view
.accept_mentity
(mpackage
) then continue
207 # Collect all packages that directly depends on `self`
208 redef fun collect_children
(view
) do
209 var res
= new HashSet[MENTITY]
210 for mpackage
in view
.mpackages
do
211 if mpackage
.collect_parents
(view
).has
(self) then res
.add mpackage
216 # Collect all groups contained in `self`
217 fun collect_all_mgroups
(view
: ModelView): HashSet[MGroup] do
218 var res
= new HashSet[MGroup]
219 for mgroup
in mgroups
do
220 if not view
.accept_mentity
(mgroup
) then continue
226 # Collect only groups contained in `self.root`
227 fun collect_mgroups
(view
: ModelView): HashSet[MGroup] do
228 var res
= new HashSet[MGroup]
230 if root
== null then return res
231 res
.add_all root
.collect_mgroups
(view
)
235 # Collect all modules contained in `self`
236 fun collect_all_mmodules
(view
: ModelView): HashSet[MModule] do
237 var res
= new HashSet[MModule]
238 for mgroup
in collect_mgroups
(view
) do
239 res
.add_all mgroup
.collect_mmodules
(view
)
244 # Collect only modules contained in `self.root`
245 fun collect_mmodules
(view
: ModelView): HashSet[MModule] do
246 var res
= new HashSet[MModule]
248 if root
== null then return res
249 res
.add_all root
.collect_mmodules
(view
)
253 # Collect all classes introduced in `self`
254 fun collect_intro_mclasses
(view
: ModelView): HashSet[MClass] do
255 var res
= new HashSet[MClass]
256 for mgroup
in mgroups
do
257 for mmodule
in collect_all_mmodules
(view
) do
258 res
.add_all mmodule
.collect_intro_mclasses
(view
)
264 # Collect all classes redefined or refined in `self`
265 fun collect_redef_mclasses
(view
: ModelView): Set[MClass] do
266 var res
= new HashSet[MClass]
267 for mgroup
in mgroups
do
268 for mmodule
in collect_all_mmodules
(view
) do
269 res
.add_all mmodule
.collect_redef_mclasses
(view
)
275 # Collect all properties introduced in `self`
276 fun collect_intro_mproperties
(view
: ModelView): HashSet[MProperty] do
277 var res
= new HashSet[MProperty]
278 for mgroup
in mgroups
do
279 for mmodule
in collect_all_mmodules
(view
) do
280 res
.add_all mmodule
.collect_intro_mproperties
(view
)
286 # Collect all properties redefined in `self`
287 fun collect_redef_mproperties
(view
: ModelView): HashSet[MProperty] do
288 var res
= new HashSet[MProperty]
289 for mgroup
in mgroups
do
290 for mmodule
in collect_all_mmodules
(view
) do
291 res
.add_all mmodule
.collect_redef_mproperties
(view
)
297 # Collect all attributes introduced in `self`
298 fun collect_intro_attributes
(view
: ModelView): Set[MAttribute] do
299 var res
= new HashSet[MAttribute]
300 for mgroup
in mgroups
do
301 for mmodule
in collect_all_mmodules
(view
) do
302 res
.add_all mmodule
.collect_intro_attributes
(view
)
308 # Collect all inits introduced in `self`
309 fun collect_intro_inits
(view
: ModelView): Set[MMethod] do
310 var res
= new HashSet[MMethod]
311 for mgroup
in mgroups
do
312 for mmodule
in collect_all_mmodules
(view
) do
313 res
.add_all mmodule
.collect_intro_inits
(view
)
319 # Collect all methods introduced in `self` excluding inits
321 # See `collect_intro_inits`.
322 fun collect_intro_methods
(view
: ModelView): Set[MMethod] do
323 var res
= new HashSet[MMethod]
324 for mgroup
in mgroups
do
325 for mmodule
in collect_all_mmodules
(view
) do
326 res
.add_all mmodule
.collect_intro_methods
(view
)
332 # Collect all virtual types introduced in `self`
333 fun collect_intro_vts
(view
: ModelView): Set[MVirtualTypeProp] do
334 var res
= new HashSet[MVirtualTypeProp]
335 for mgroup
in mgroups
do
336 for mmodule
in collect_all_mmodules
(view
) do
337 res
.add_all mmodule
.collect_intro_vts
(view
)
346 redef fun collect_modifiers
do return super + ["group"]
348 # Collect all groups directly import by `self`
349 redef fun collect_parents
(view
) do
350 var res
= new HashSet[MENTITY]
351 for mmodule
in mmodules
do
352 for parent
in mmodule
.collect_parents
(view
) do
353 var mgroup
= parent
.mgroup
354 if mgroup
== null or mgroup
== self then continue
355 if not view
.accept_mentity
(mgroup
) then continue
362 # Collect all group that directly import `self`
363 redef fun collect_children
(view
) do
364 var res
= new HashSet[MENTITY]
365 for mgroup
in view
.mgroups
do
366 if mgroup
== self or not view
.accept_mentity
(mgroup
) then continue
367 if mgroup
.collect_parents
(view
).has
(self) then res
.add mgroup
372 # Collect all groups contained in `self`
373 fun collect_mgroups
(view
: ModelView): HashSet[MENTITY] do
374 var res
= new HashSet[MENTITY]
375 for mgroup
in in_nesting
.direct_smallers
do
376 if not view
.accept_mentity
(mgroup
) then continue
382 # Collect all modules contained in `self`
383 fun collect_mmodules
(view
: ModelView): HashSet[MModule] do
384 var res
= new HashSet[MModule]
385 for mmodule
in mmodules
do
386 if not view
.accept_mentity
(mmodule
) then continue
395 redef fun collect_modifiers
do return super + ["module"]
397 # Collect all module ancestors of `self` (direct and transitive imports)
398 redef fun collect_ancestors
(view
) do
399 var res
= new HashSet[MENTITY]
400 for mentity
in in_importation
.greaters
do
401 if mentity
== self then continue
402 if not view
.accept_mentity
(mentity
) then continue
408 # Collect all modules directly imported by `self`
409 redef fun collect_parents
(view
) do
410 var res
= new HashSet[MENTITY]
411 for mentity
in in_importation
.direct_greaters
do
412 if mentity
== self then continue
413 if not view
.accept_mentity
(mentity
) then continue
419 # Collect all modules that directly import `self`
420 redef fun collect_children
(view
) do
421 var res
= new HashSet[MENTITY]
422 for mentity
in in_importation
.direct_smallers
do
423 if mentity
== self then continue
424 if not view
.accept_mentity
(mentity
) then continue
430 # Collect all module descendants of `self` (direct and transitive imports)
431 redef fun collect_descendants
(view
) do
432 var res
= new HashSet[MENTITY]
433 for mentity
in in_importation
.smallers
do
434 if mentity
== self then continue
435 if not view
.accept_mentity
(mentity
) then continue
441 # Collect all class definitions introduced in `self`
442 fun collect_intro_mclassdefs
(view
: ModelView): Set[MClassDef] do
443 var res
= new HashSet[MClassDef]
444 for mclassdef
in mclassdefs
do
445 if not mclassdef
.is_intro
then continue
446 if not view
.accept_mentity
(mclassdef
) then continue
452 # Collect all class definitions refined in `self`
453 fun collect_redef_mclassdefs
(view
: ModelView): Set[MClassDef] do
454 var res
= new HashSet[MClassDef]
455 for mclassdef
in mclassdefs
do
456 if mclassdef
.is_intro
then continue
457 if not view
.accept_mentity
(mclassdef
) then continue
463 # Collect all class definitions introduced and refined in `self`
464 fun collect_local_mclassdefs
(view
: ModelView): Set[MClassDef] do
465 var res
= new HashSet[MClassDef]
466 res
.add_all collect_intro_mclassdefs
(view
)
467 res
.add_all collect_redef_mclassdefs
(view
)
471 # Collect all classes introduced in `self`
472 fun collect_intro_mclasses
(view
: ModelView): Set[MClass] do
473 var res
= new HashSet[MClass]
474 for mclass
in intro_mclasses
do
475 if not view
.accept_mentity
(mclass
) then continue
481 # Collect all classes refined in `self`
482 fun collect_redef_mclasses
(view
: ModelView): Set[MClass] do
483 var mclasses
= new HashSet[MClass]
484 for mclassdef
in mclassdefs
do
485 if not view
.accept_mentity
(mclassdef
.mclass
) then continue
486 if not mclassdef
.is_intro
then mclasses
.add
(mclassdef
.mclass
)
491 # Collect all classes introduced and refined in `self`
492 fun collect_local_mclasses
(view
: ModelView): Set[MClass] do
493 var res
= new HashSet[MClass]
494 res
.add_all collect_intro_mclasses
(view
)
495 res
.add_all collect_redef_mclasses
(view
)
499 # Collect all classes imported from `self` parents
500 fun collect_imported_mclasses
(view
: ModelView): Set[MClass] do
501 var res
= new HashSet[MClass]
502 for parent
in collect_parents
(view
) do
503 res
.add_all parent
.collect_intro_mclasses
(view
)
504 res
.add_all parent
.collect_redef_mclasses
(view
)
505 res
.add_all parent
.collect_imported_mclasses
(view
)
510 # Collect all properties introduced in `self`
511 fun collect_intro_mproperties
(view
: ModelView): Set[MProperty] do
512 var res
= new HashSet[MProperty]
513 for mclass
in collect_intro_mclasses
(view
) do
514 res
.add_all mclass
.collect_intro_mproperties
(view
)
519 # Collect properties redefined in `self`
520 fun collect_redef_mproperties
(view
: ModelView): Set[MProperty] do
521 var res
= new HashSet[MProperty]
522 for mclassdef
in mclassdefs
do
523 for mpropdef
in mclassdef
.collect_redef_mpropdefs
(view
) do
524 res
.add mpropdef
.mproperty
530 # Collect attributes introduced in `self`
531 fun collect_intro_attributes
(view
: ModelView): Set[MAttribute] do
532 var res
= new HashSet[MAttribute]
533 for mproperty
in collect_intro_mproperties
(view
) do
534 if mproperty
isa MAttribute then res
.add
(mproperty
)
539 # Collect all inits introduced in `self`
540 fun collect_intro_inits
(view
: ModelView): Set[MMethod] do
541 var res
= new HashSet[MMethod]
542 for mproperty
in collect_intro_mproperties
(view
) do
543 if mproperty
isa MMethod and mproperty
.is_init
then res
.add
(mproperty
)
548 # Collect methods introduced in `self` (without inits)
549 fun collect_intro_methods
(view
: ModelView): Set[MMethod] do
550 var res
= new HashSet[MMethod]
551 for mproperty
in collect_intro_mproperties
(view
) do
552 if mproperty
isa MMethod and not mproperty
.is_init
then res
.add
(mproperty
)
557 # Collect virtual types introduced in `self`
558 fun collect_intro_vts
(view
: ModelView): Set[MVirtualTypeProp] do
559 var res
= new HashSet[MVirtualTypeProp]
560 for mproperty
in collect_intro_mproperties
(view
) do
561 if mproperty
isa MVirtualTypeProp then res
.add
(mproperty
)
569 redef fun collect_modifiers
do return intro
.collect_modifiers
571 redef fun collect_linearization
(mainmodule
) do
572 var mclassdefs
= self.mclassdefs
.to_a
573 mainmodule
.linearize_mclassdefs
(mclassdefs
)
577 # Collect all direct parents of `self`
579 # This method uses a flattened hierarchy containing all the mclassdefs.
580 redef fun collect_parents
(view
) do
581 var res
= new HashSet[MENTITY]
582 for mclass
in in_hierarchy
(view
.mainmodule
).direct_greaters
do
583 if mclass
== self or not view
.accept_mentity
(mclass
) then continue
589 # Collect all direct children of `self`
591 # This method uses a flattened hierarchy containing all the mclassdefs.
592 redef fun collect_children
(view
) do
593 var res
= new HashSet[MENTITY]
594 for mclass
in in_hierarchy
(view
.mainmodule
).direct_smallers
do
595 if mclass
== self or not view
.accept_mentity
(mclass
) then continue
601 # Collect all class definitions of `self`
602 fun collect_mclassdefs
(view
: ModelView): Set[MClassDef] do
603 var res
= new HashSet[MClassDef]
604 for mclassdef
in mclassdefs
do
605 if not view
.accept_mentity
(mclassdef
) then continue
611 # Collect all property definitions that are introductions in `self`
612 fun collect_intro_mpropdefs
(view
: ModelView): Set[MPropDef] do
613 var set
= new HashSet[MPropDef]
614 for mclassdef
in mclassdefs
do
615 for mpropdef
in mclassdef
.mpropdefs
do
616 if not mpropdef
.is_intro
then continue
617 if not view
.accept_mentity
(mpropdef
) then continue
624 # Collect all properties introduced in `self`
625 fun collect_intro_mproperties
(view
: ModelView): Set[MProperty] do
626 var set
= new HashSet[MProperty]
627 for mclassdef
in mclassdefs
do
628 for mprop
in mclassdef
.intro_mproperties
do
629 if not view
.accept_mentity
(mprop
) then continue
636 # Collect all propierty definitions that are redefinition in `self`
637 fun collect_redef_mpropdefs
(view
: ModelView): Set[MPropDef] do
638 var set
= new HashSet[MPropDef]
639 for mclassdef
in mclassdefs
do
640 for mpropdef
in mclassdef
.mpropdefs
do
641 if mpropdef
.is_intro
then continue
642 if not view
.accept_mentity
(mpropdef
) then continue
649 # Collect all properties redefined in `self`
650 fun collect_redef_mproperties
(view
: ModelView): Set[MProperty] do
651 var set
= new HashSet[MProperty]
652 for mclassdef
in mclassdefs
do
653 for mpropdef
in mclassdef
.mpropdefs
do
654 if mpropdef
.mproperty
.intro_mclassdef
.mclass
== self then continue
655 if not view
.accept_mentity
(mpropdef
) then continue
656 set
.add
(mpropdef
.mproperty
)
662 # Collect all properties introduced and redefined in `self`
663 fun collect_local_mproperties
(view
: ModelView): Set[MProperty] do
664 var set
= new HashSet[MProperty]
665 set
.add_all collect_intro_mproperties
(view
)
666 set
.add_all collect_redef_mproperties
(view
)
670 # Collect all properties inehrited by `self`
671 fun collect_inherited_mproperties
(view
: ModelView): Set[MProperty] do
672 var set
= new HashSet[MProperty]
673 for parent
in collect_parents
(view
) do
674 set
.add_all
(parent
.collect_intro_mproperties
(view
))
675 set
.add_all
(parent
.collect_inherited_mproperties
(view
))
680 # Collect all properties accessible by `self`
682 # This include introduced, redefined, inherited properties.
683 fun collect_accessible_mproperties
(view
: ModelView): Set[MProperty] do
684 var set
= new HashSet[MProperty]
685 set
.add_all
(collect_intro_mproperties
(view
))
686 set
.add_all
(collect_redef_mproperties
(view
))
687 set
.add_all
(collect_inherited_mproperties
(view
))
691 # Collect all methods introduced in `self`
692 fun collect_intro_mmethods
(view
: ModelView): Set[MMethod] do
693 var res
= new HashSet[MMethod]
694 for mproperty
in collect_intro_mproperties
(view
) do
695 if mproperty
isa MMethod then res
.add
(mproperty
)
700 # Collect all methods redefined in `self`
701 fun collect_redef_mmethods
(view
: ModelView): Set[MMethod] do
702 var res
= new HashSet[MMethod]
703 for mproperty
in collect_redef_mproperties
(view
) do
704 if mproperty
isa MMethod then res
.add
(mproperty
)
709 # Collect all methods introduced and redefined in `self`
710 fun collect_local_mmethods
(view
: ModelView): Set[MMethod] do
711 var set
= new HashSet[MMethod]
712 set
.add_all collect_intro_mmethods
(view
)
713 set
.add_all collect_redef_mmethods
(view
)
717 # Collect all methods inherited by `self`
718 fun collect_inherited_mmethods
(view
: ModelView): Set[MMethod] do
719 var res
= new HashSet[MMethod]
720 for mproperty
in collect_inherited_mproperties
(view
) do
721 if mproperty
isa MMethod then res
.add
(mproperty
)
726 # Collect all methods accessible by `self`
728 # This include introduced, redefined, inherited methods.
729 fun collect_accessible_mmethods
(view
: ModelView): Set[MMethod] do
730 var set
= new HashSet[MMethod]
731 set
.add_all
(collect_intro_mmethods
(view
))
732 set
.add_all
(collect_redef_mmethods
(view
))
733 set
.add_all
(collect_inherited_mmethods
(view
))
737 # Collect all attributes introduced in `self`
738 fun collect_intro_mattributes
(view
: ModelView): Set[MAttribute] do
739 var res
= new HashSet[MAttribute]
740 for mproperty
in collect_intro_mproperties
(view
) do
741 if mproperty
isa MAttribute then res
.add
(mproperty
)
746 # Collect all attributes redefined in `self`
747 fun collect_redef_mattributes
(view
: ModelView): Set[MAttribute] do
748 var res
= new HashSet[MAttribute]
749 for mproperty
in collect_redef_mproperties
(view
) do
750 if mproperty
isa MAttribute then res
.add
(mproperty
)
755 # Collect all attributes introduced and redefined in `self`
756 fun collect_local_mattributes
(view
: ModelView): Set[MAttribute] do
757 var set
= new HashSet[MAttribute]
758 set
.add_all collect_intro_mattributes
(view
)
759 set
.add_all collect_redef_mattributes
(view
)
763 # Collect all attributes inherited by `self`
764 fun collect_inherited_mattributes
(view
: ModelView): Set[MAttribute] do
765 var res
= new HashSet[MAttribute]
766 for mproperty
in collect_inherited_mproperties
(view
) do
767 if mproperty
isa MAttribute then res
.add
(mproperty
)
772 # Collect all attributes accessible by `self`
774 # This include introduced, redefined, inherited mattributes.
775 fun collect_accessible_mattributes
(view
: ModelView): Set[MAttribute] do
776 var set
= new HashSet[MAttribute]
777 set
.add_all
(collect_intro_mattributes
(view
))
778 set
.add_all
(collect_redef_mattributes
(view
))
779 set
.add_all
(collect_inherited_mattributes
(view
))
783 # Collect all init methods introduced in `self`
784 fun collect_intro_inits
(view
: ModelView): Set[MMethod] do
785 var res
= new HashSet[MMethod]
786 for mproperty
in collect_intro_mmethods
(view
) do
787 if mproperty
.is_init
then res
.add
(mproperty
)
792 # Collect all init methods redefined in `self`
793 fun collect_redef_inits
(view
: ModelView): Set[MMethod] do
794 var res
= new HashSet[MMethod]
795 for mproperty
in collect_redef_mmethods
(view
) do
796 if mproperty
.is_init
then res
.add
(mproperty
)
801 # Collect all init methods introduced and redefined in `self`
802 fun collect_local_inits
(view
: ModelView): Set[MMethod] do
803 var set
= new HashSet[MMethod]
804 set
.add_all collect_intro_inits
(view
)
805 set
.add_all collect_redef_inits
(view
)
809 # Collect all init methods inherited by `self`
810 fun collect_inherited_inits
(view
: ModelView): Set[MMethod] do
811 var res
= new HashSet[MMethod]
812 for mproperty
in collect_inherited_mmethods
(view
) do
813 if mproperty
.is_init
then res
.add
(mproperty
)
818 # Collect all init methods accessible by `self`
820 # This include introduced, redefined, inherited inits.
821 fun collect_accessible_inits
(view
: ModelView): Set[MMethod] do
822 var set
= new HashSet[MMethod]
823 set
.add_all
(collect_intro_inits
(view
))
824 set
.add_all
(collect_redef_inits
(view
))
825 set
.add_all
(collect_inherited_inits
(view
))
829 # Collect all virtual types introduced in `self`
830 fun collect_intro_vts
(view
: ModelView): Set[MVirtualTypeProp] do
831 var res
= new HashSet[MVirtualTypeProp]
832 for mproperty
in collect_intro_mproperties
(view
) do
833 if mproperty
isa MVirtualTypeProp then res
.add
(mproperty
)
838 # Collect all virtual types redefined in `self`
839 fun collect_redef_vts
(view
: ModelView): Set[MVirtualTypeProp] do
840 var res
= new HashSet[MVirtualTypeProp]
841 for mproperty
in collect_intro_mproperties
(view
) do
842 if mproperty
isa MVirtualTypeProp then res
.add
(mproperty
)
847 # Collect all virtual types introduced or redefined in `self`
848 fun collect_local_vts
(view
: ModelView): Set[MVirtualTypeProp] do
849 var set
= new HashSet[MVirtualTypeProp]
850 set
.add_all collect_intro_vts
(view
)
851 set
.add_all collect_redef_vts
(view
)
855 # Collect all virtual types inherited by `self`
856 fun collect_inherited_vts
(view
: ModelView): Set[MVirtualTypeProp] do
857 var res
= new HashSet[MVirtualTypeProp]
858 for mproperty
in collect_inherited_mproperties
(view
) do
859 if mproperty
isa MVirtualTypeProp then res
.add
(mproperty
)
864 # Collect all virtual types accessible by `self`
866 # This include introduced, redefined, inherited virtual types.
867 fun collect_accessible_vts
(view
: ModelView): Set[MVirtualTypeProp] do
868 var set
= new HashSet[MVirtualTypeProp]
869 for mproperty
in collect_accessible_mproperties
(view
) do
870 if mproperty
isa MVirtualTypeProp then set
.add mproperty
876 redef class MClassDef
878 redef fun collect_modifiers
do
883 res
.add mclass
.visibility
.to_s
885 res
.add mclass
.kind
.to_s
889 redef fun collect_linearization
(mainmodule
) do
890 var mclassdefs
= new Array[MClassDef]
891 for mclassdef
in in_hierarchy
.as(not null).greaters
do
892 if mclassdef
.mclass
== self.mclass
then mclassdefs
.add mclassdef
894 mainmodule
.linearize_mclassdefs
(mclassdefs
)
898 redef fun collect_ancestors
(view
) do
899 var res
= new HashSet[MENTITY]
900 var hierarchy
= self.in_hierarchy
901 if hierarchy
== null then return res
902 for parent
in hierarchy
.greaters
do
903 if parent
== self or not view
.accept_mentity
(parent
) then continue
909 redef fun collect_parents
(view
) do
910 var res
= new HashSet[MENTITY]
911 var hierarchy
= self.in_hierarchy
912 if hierarchy
== null then return res
913 for parent
in hierarchy
.direct_greaters
do
914 if parent
== self or not view
.accept_mentity
(parent
) then continue
920 redef fun collect_children
(view
) do
921 var res
= new HashSet[MENTITY]
922 var hierarchy
= self.in_hierarchy
923 if hierarchy
== null then return res
924 for child
in hierarchy
.direct_smallers
do
925 if child
== self or not view
.accept_mentity
(child
) then continue
931 # Collect all property definitions in `self`
932 fun collect_mpropdefs
(view
: ModelView): Set[MPropDef] do
933 var res
= new HashSet[MPropDef]
934 for mpropdef
in mpropdefs
do
935 if not view
.accept_mentity
(mpropdef
) then continue
941 # Collect all attribute definitions in `self`
942 fun collect_mattributedefs
(view
: ModelView): Set[MAttributeDef] do
943 var res
= new HashSet[MAttributeDef]
944 for mpropdef
in collect_mpropdefs
(view
) do
945 if not mpropdef
isa MAttributeDef then continue
951 # Collect all methods definitions in `self`
952 fun collect_mmethoddefs
(view
: ModelView): Set[MMethodDef] do
953 var res
= new HashSet[MMethodDef]
954 for mpropdef
in collect_mpropdefs
(view
) do
955 if not mpropdef
isa MMethodDef then continue
961 # Collect all virtual types definitions in `self`
962 fun collect_mtypedefs
(view
: ModelView): Set[MVirtualTypeDef] do
963 var res
= new HashSet[MVirtualTypeDef]
964 for mpropdef
in collect_mpropdefs
(view
) do
965 if not mpropdef
isa MVirtualTypeDef then continue
971 # Collect all property definitions that are introduction in `self`
972 fun collect_intro_mpropdefs
(view
: ModelView): Set[MPropDef] do
973 var res
= new HashSet[MPropDef]
974 for mpropdef
in mpropdefs
do
975 if not mpropdef
.is_intro
then continue
976 if not view
.accept_mentity
(mpropdef
) then continue
982 # Collect all property definitions that are redefinition in `self`
983 fun collect_redef_mpropdefs
(view
: ModelView): Set[MPropDef] do
984 var res
= new HashSet[MPropDef]
985 for mpropdef
in mpropdefs
do
986 if mpropdef
.is_intro
then continue
987 if not view
.accept_mentity
(mpropdef
) then continue
994 redef class MProperty
995 redef fun collect_modifiers
do return intro
.collect_modifiers
997 redef fun collect_linearization
(mainmodule
) do
998 var mpropdefs
= self.mpropdefs
.to_a
999 mainmodule
.linearize_mpropdefs
(mpropdefs
)
1003 # Collect all property definitions of `self`
1004 fun collect_mpropdefs
(view
: ModelView): Set[MPropDef] do
1005 var res
= new HashSet[MPropDef]
1006 for mpropdef
in mpropdefs
do
1007 if not view
.accept_mentity
(mpropdef
) then continue
1013 # Collect all direct super definitions of `self`
1014 redef fun collect_parents
(view
) do
1015 var res
= new HashSet[MENTITY]
1016 for mpropdef
in mpropdefs
do
1017 for parent
in mpropdef
.collect_parents
(view
) do
1018 if not view
.accept_mentity
(parent
) then continue
1019 res
.add parent
.mproperty
1025 # Collection all definitions that have `self` as a direct super definition
1026 redef fun collect_children
(view
) do
1027 var res
= new HashSet[MENTITY]
1028 for mpropdef
in mpropdefs
do
1029 for child
in mpropdef
.collect_parents
(view
) do
1030 if not view
.accept_mentity
(child
) then continue
1031 res
.add child
.mproperty
1038 redef class MPropDef
1040 redef fun collect_modifiers
do
1042 if not is_intro
then
1045 res
.add mproperty
.visibility
.to_s
1048 if mprop
isa MVirtualTypeDef then
1050 else if mprop
isa MMethodDef then
1051 if mprop
.is_abstract
then
1053 else if mprop
.is_intern
then
1056 if mprop
.mproperty
.is_init
then
1061 else if mprop
isa MAttributeDef then
1067 redef fun collect_linearization
(mainmodule
) do
1068 var mpropdefs
= new Array[MPropDef]
1070 while not mentity
.is_intro
do
1071 mpropdefs
.add mentity
1072 mentity
= mentity
.lookup_next_definition
(mainmodule
, mentity
.mclassdef
.bound_mtype
)
1074 mpropdefs
.add mentity
1075 mainmodule
.linearize_mpropdefs
(mpropdefs
)
1079 # Collect only the next definition of `self`
1080 redef fun collect_parents
(view
) do
1081 var res
= new HashSet[MENTITY]
1083 while not mpropdef
.is_intro
do
1084 mpropdef
= mpropdef
.lookup_next_definition
(mclassdef
.mmodule
, mclassdef
.bound_mtype
)
1090 # Collect all children definitions that directly depend on `self`
1091 redef fun collect_children
(view
) do
1092 var res
= new HashSet[MENTITY]
1093 for mpropdef
in mproperty
.collect_mpropdefs
(view
) do
1094 if mpropdef
.collect_parents
(view
).has
(self) then res
.add mpropdef