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

Property definitions

nitc :: model_collect $ MEntity :: hierarchy_poset
	# 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(mainmodule: MModule, filter: nullable ModelFilter): POSet[MENTITY] do
		var poset = new POSet[MENTITY]
		var parents_done = new HashSet[MENTITY]
		var parents = new Array[MENTITY]
		parents.add self
		while parents.not_empty do
			var mentity = parents.pop
			if parents_done.has(mentity) then continue
			parents_done.add mentity
			poset.add_node mentity
			for parent in mentity.collect_parents(mainmodule, filter) do
				poset.add_edge(mentity, parent)
				parents.add parent
			end
		end
		var children_done = new HashSet[MEntity]
		var children = new Array[MEntity]
		children.add self
		while children.not_empty do
			var mentity = children.pop
			if children_done.has(mentity) then continue
			children_done.add mentity
			for child in mentity.collect_children(mainmodule, filter) do
				poset.add_edge(child, mentity)
				children.add child
			end
		end
		return poset
	end
src/model/model_collect.nit:105,2--145,4