+
+ # Collect `self` linearization anchored on `mainmodule`.
+ fun collect_linearization(mainmodule: MModule): nullable Array[MEntity] do
+ return null
+ end
+
+ # Collect `self` ancestors (direct and indirect).
+ #
+ # The concept of ancestor is abstract at this stage.
+ fun collect_ancestors(view: ModelView): Set[MENTITY] do
+ var done = new HashSet[MENTITY]
+ var todo = new Array[MENTITY]
+
+ todo.add_all collect_parents(view)
+ while todo.not_empty do
+ var mentity = todo.pop
+ if mentity == self or done.has(mentity) then continue
+ print "{mentity} == {self}"
+ done.add mentity
+ todo.add_all mentity.collect_parents(view)
+ end
+ return done
+ end
+
+ # Collect `self` parents (direct ancestors).
+ #
+ # The concept of parent is abstract at this stage.
+ fun collect_parents(view: ModelView): Set[MENTITY] is abstract
+
+ # Collect `self` children (direct descendants).
+ #
+ # The concept of child is abstract at this stage.
+ fun collect_children(view: ModelView): Set[MENTITY] is abstract
+
+ # Collect `self` descendants (direct and direct).
+ #
+ # The concept of descendant is abstract at this stage.
+ fun collect_descendants(view: ModelView): Set[MENTITY] do
+ var done = new HashSet[MENTITY]
+ var todo = new Array[MENTITY]
+
+ todo.add_all collect_children(view)
+ while todo.not_empty do
+ var mentity = todo.pop
+ if mentity == self or done.has(mentity) then continue
+ done.add mentity
+ todo.add_all mentity.collect_children(view)
+ end
+ return done
+ end
+
+ # Build a poset representing `self` in it's own hierarchy.
+ #
+ # The notion of hierarchy depends on the type of MEntity.
+ #
+ # Here a recap:
+ # * MPackage: package dependencies
+ # * MGroup: group dependencies
+ # * MModule: modules imports
+ # * MClass: class inheritance (all classdefs flattened)
+ # * MClassDef: classdef inheritance
+ # * MProperty: property definitions graph (all propdefs flattened)
+ # * MPropDef: property definitions graph
+ fun hierarchy_poset(view: ModelView): POSet[MENTITY] do
+ var done = new HashSet[MENTITY]
+ var mentities = new Array[MENTITY]
+ mentities.add self
+ var poset = new POSet[MENTITY]
+ while mentities.not_empty do
+ var mentity = mentities.pop
+ if done.has(mentity) then continue
+ done.add mentity
+ poset.add_node mentity
+ for parent in mentity.collect_parents(view) do
+ poset.add_edge(mentity, parent)
+ mentities.add parent
+ end
+ for child in mentity.collect_children(view) do
+ poset.add_edge(child, mentity)
+ mentities.add child
+ end
+ end
+ return poset
+ end