Graph for mentity hierarchies

Recursively build parents and children list from a center.

Introduced properties

private var _center: MEntity

nitc :: InheritanceGraph :: _center

MEntity at the center of this graph
private var _filter: nullable ModelFilter

nitc :: InheritanceGraph :: _filter

Filter to apply on model if any
private var _graph: DotGraph

nitc :: InheritanceGraph :: _graph

Graph generated
private var _mainmodule: MModule

nitc :: InheritanceGraph :: _mainmodule

Mainmodule for class linearization
private var _model: Model

nitc :: InheritanceGraph :: _model

Model used to build graph from
fun center: MEntity

nitc :: InheritanceGraph :: center

MEntity at the center of this graph
protected fun center=(center: MEntity)

nitc :: InheritanceGraph :: center=

MEntity at the center of this graph
init defaultinit(center: MEntity, model: Model, mainmodule: MModule, filter: nullable ModelFilter)

nitc :: InheritanceGraph :: defaultinit

private fun done_children=(done_children: HashSet[MEntity])

nitc :: InheritanceGraph :: done_children=

private fun done_parents=(done_parents: HashSet[MEntity])

nitc :: InheritanceGraph :: done_parents=

fun dotdotdot(id: String): DotNode

nitc :: InheritanceGraph :: dotdotdot

Generate a ... node
fun draw(parents_depth: nullable Int, children_depth: nullable Int): DotGraph

nitc :: InheritanceGraph :: draw

Build the graph
fun draw_children(mentity: MEntity, max_depth: nullable Int, current_depth: nullable Int)

nitc :: InheritanceGraph :: draw_children

Recursively draw children of mentity
fun draw_edge(from: MEntity, to: MEntity): DotEdge

nitc :: InheritanceGraph :: draw_edge

Draw a edges between two mentities
fun draw_node(mentity: MEntity): DotElement

nitc :: InheritanceGraph :: draw_node

Draw a node from a mentity
fun draw_parents(mentity: MEntity, max_depth: nullable Int, current_depth: nullable Int)

nitc :: InheritanceGraph :: draw_parents

Recursively draw parents of mentity
fun filter: nullable ModelFilter

nitc :: InheritanceGraph :: filter

Filter to apply on model if any
protected fun filter=(filter: nullable ModelFilter)

nitc :: InheritanceGraph :: filter=

Filter to apply on model if any
fun from_dotdotdot(mentity: MEntity): DotEdge

nitc :: InheritanceGraph :: from_dotdotdot

Create a link from a ... node to a mentity
fun graph: DotGraph

nitc :: InheritanceGraph :: graph

Graph generated
protected fun graph=(graph: DotGraph)

nitc :: InheritanceGraph :: graph=

Graph generated
fun highlight(dot: DotElement): DotElement

nitc :: InheritanceGraph :: highlight

Change the border color of the node
fun mainmodule: MModule

nitc :: InheritanceGraph :: mainmodule

Mainmodule for class linearization
protected fun mainmodule=(mainmodule: MModule)

nitc :: InheritanceGraph :: mainmodule=

Mainmodule for class linearization
fun model: Model

nitc :: InheritanceGraph :: model

Model used to build graph from
protected fun model=(model: Model)

nitc :: InheritanceGraph :: model=

Model used to build graph from
private fun nodes=(nodes: HashMap[MEntity, DotElement])

nitc :: InheritanceGraph :: nodes=

fun to_dotdotdot(mentity: MEntity): DotEdge

nitc :: InheritanceGraph :: to_dotdotdot

Create a link from mentity to a ... node
private fun to_dots=(to_dots: HashMap[MEntity, DotElement])

nitc :: InheritanceGraph :: to_dots=

Redefined properties

redef type SELF: InheritanceGraph

nitc $ InheritanceGraph :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _center: MEntity

nitc :: InheritanceGraph :: _center

MEntity at the center of this graph
private var _filter: nullable ModelFilter

nitc :: InheritanceGraph :: _filter

Filter to apply on model if any
private var _graph: DotGraph

nitc :: InheritanceGraph :: _graph

Graph generated
private var _mainmodule: MModule

nitc :: InheritanceGraph :: _mainmodule

Mainmodule for class linearization
private var _model: Model

nitc :: InheritanceGraph :: _model

Model used to build graph from
fun center: MEntity

nitc :: InheritanceGraph :: center

MEntity at the center of this graph
protected fun center=(center: MEntity)

nitc :: InheritanceGraph :: center=

MEntity at the center of this graph
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
init defaultinit(center: MEntity, model: Model, mainmodule: MModule, filter: nullable ModelFilter)

nitc :: InheritanceGraph :: defaultinit

private fun done_children=(done_children: HashSet[MEntity])

nitc :: InheritanceGraph :: done_children=

private fun done_parents=(done_parents: HashSet[MEntity])

nitc :: InheritanceGraph :: done_parents=

fun dotdotdot(id: String): DotNode

nitc :: InheritanceGraph :: dotdotdot

Generate a ... node
fun draw(parents_depth: nullable Int, children_depth: nullable Int): DotGraph

nitc :: InheritanceGraph :: draw

Build the graph
fun draw_children(mentity: MEntity, max_depth: nullable Int, current_depth: nullable Int)

nitc :: InheritanceGraph :: draw_children

Recursively draw children of mentity
fun draw_edge(from: MEntity, to: MEntity): DotEdge

nitc :: InheritanceGraph :: draw_edge

Draw a edges between two mentities
fun draw_node(mentity: MEntity): DotElement

nitc :: InheritanceGraph :: draw_node

Draw a node from a mentity
fun draw_parents(mentity: MEntity, max_depth: nullable Int, current_depth: nullable Int)

nitc :: InheritanceGraph :: draw_parents

Recursively draw parents of mentity
fun filter: nullable ModelFilter

nitc :: InheritanceGraph :: filter

Filter to apply on model if any
protected fun filter=(filter: nullable ModelFilter)

nitc :: InheritanceGraph :: filter=

Filter to apply on model if any
fun from_dotdotdot(mentity: MEntity): DotEdge

nitc :: InheritanceGraph :: from_dotdotdot

Create a link from a ... node to a mentity
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun graph: DotGraph

nitc :: InheritanceGraph :: graph

Graph generated
protected fun graph=(graph: DotGraph)

nitc :: InheritanceGraph :: graph=

Graph generated
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun highlight(dot: DotElement): DotElement

nitc :: InheritanceGraph :: highlight

Change the border color of the node
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun mainmodule: MModule

nitc :: InheritanceGraph :: mainmodule

Mainmodule for class linearization
protected fun mainmodule=(mainmodule: MModule)

nitc :: InheritanceGraph :: mainmodule=

Mainmodule for class linearization
fun model: Model

nitc :: InheritanceGraph :: model

Model used to build graph from
protected fun model=(model: Model)

nitc :: InheritanceGraph :: model=

Model used to build graph from
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
private fun nodes=(nodes: HashMap[MEntity, DotElement])

nitc :: InheritanceGraph :: nodes=

intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun to_dotdotdot(mentity: MEntity): DotEdge

nitc :: InheritanceGraph :: to_dotdotdot

Create a link from mentity to a ... node
private fun to_dots=(to_dots: HashMap[MEntity, DotElement])

nitc :: InheritanceGraph :: to_dots=

abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram nitc::InheritanceGraph InheritanceGraph core::Object Object nitc::InheritanceGraph->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

nitc $ InheritanceGraph
# Graph for mentity hierarchies
#
# Recursively build parents and children list from a `center`.
class InheritanceGraph

	# MEntity at the center of this graph
	var center: MEntity

	# Model used to build graph from
	var model: Model

	# Mainmodule for class linearization
	var mainmodule: MModule

	# Filter to apply on model if any
	var filter: nullable ModelFilter

	# Graph generated
	var graph: DotGraph is lazy do
		var graph = new DotGraph("package_diagram", "digraph")

		graph["compound"] = "true"
		graph["rankdir"] = "BT"
		graph["ranksep"] = 0.3
		graph["nodesep"] = 0.3

		graph.nodes_attrs["margin"] = 0.1
		graph.nodes_attrs["width"] = 0
		graph.nodes_attrs["height"] = 0
		graph.nodes_attrs["fontsize"] = 10
		graph.nodes_attrs["fontname"] = "helvetica"

		graph.edges_attrs["dir"] = "none"
		graph.edges_attrs["color"] = "gray"

		return graph
	end

	# Build the graph
	fun draw(parents_depth, children_depth: nullable Int): DotGraph do
		draw_node center
		draw_parents(center, parents_depth)
		draw_children(center, children_depth)
		return graph
	end

	private var nodes = new HashMap[MEntity, DotElement]
	private var done_parents = new HashSet[MEntity]
	private var done_children = new HashSet[MEntity]

	# Recursively draw parents of mentity
	fun draw_parents(mentity: MEntity, max_depth: nullable Int, current_depth: nullable Int) do
		if done_parents.has(mentity) then return
		done_parents.add mentity
		current_depth = current_depth or else 0
		if max_depth != null and current_depth >= max_depth then
			from_dotdotdot(mentity)
			return
		end
		var parents = mentity.collect_parents(mainmodule, filter)
		if parents.length > 10 then
			from_dotdotdot(mentity)
			return
		end
		for parent in parents do
			if parent isa MModule then
				var mgroup = parent.mgroup
				if mgroup != null and mgroup.default_mmodule == parent then parent = mgroup
			end
			if parent isa MGroup then
				if parent.mpackage.mgroups.first == parent then parent = parent.mpackage
			end
			draw_edge(mentity, parent)
		end
		for parent in parents do
			if parent isa MModule then
				var mgroup = parent.mgroup
				if mgroup != null and mgroup.default_mmodule == parent then parent = mgroup
			end
			if parent isa MGroup then
				if parent.mpackage.mgroups.first == parent then parent = parent.mpackage
			end
			draw_parents(parent, max_depth, current_depth + 1)
		end
	end

	# Recursively draw children of mentity
	fun draw_children(mentity: MEntity, max_depth: nullable Int, current_depth: nullable Int) do
		if done_children.has(mentity) then return
		done_children.add mentity
		current_depth = current_depth or else 0
		if max_depth != null and current_depth >= max_depth then
			to_dotdotdot(mentity)
			return
		end
		var children = mentity.collect_children(mainmodule, filter)
		if children.length > 10 then
			to_dotdotdot(mentity)
			return
		end
		for child in children do
			if child isa MGroup then
				if child.mpackage.mgroups.first == child then child = child.mpackage
			end
			draw_edge(child, mentity)
		end
		for child in children do
			if child isa MGroup then
				if child.mpackage.mgroups.first == child then child = child.mpackage
			end
			draw_children(child, max_depth, current_depth + 1)
		end
	end

	# Draw a node from a `mentity`
	fun draw_node(mentity: MEntity): DotElement do
		if nodes.has_key(mentity) then return nodes[mentity]
		var node: DotElement = mentity.to_dot_node
		if mentity == center then node = highlight(node)
		nodes[mentity] = node
		graph.add node
		return node
	end

	private var edges = new HashMap2[MEntity, MEntity, DotEdge]

	# Draw a edges between two mentities
	fun draw_edge(from, to: MEntity): DotEdge do
		if edges.has(from, to) then return edges[from, to].as(not null)
		if edges.has(to, from) then return edges[to, from].as(not null)
		var nfrom = draw_node(from)
		var nto = draw_node(to)
		var edge = new DotEdge(nfrom, nto)
		edges[from, to] = edge
		graph.add edge
		return edge
	end

	private var to_dots = new HashMap[MEntity, DotElement]

	# Create a link from `mentity` to a `...` node
	fun to_dotdotdot(mentity: MEntity): DotEdge do
		var nto = draw_node(mentity)
		var dots = to_dots.get_or_null(mentity)
		if dots == null then
			dots = dotdotdot("{nto.id}...")
			to_dots[mentity] = dots
		end
		graph.add dots
		var edge = new DotEdge(dots, nto)
		graph.add edge
		return edge
	end

	private var from_dots = new HashMap[MEntity, DotElement]

	# Create a link from a `...` node to a `mentity`
	fun from_dotdotdot(mentity: MEntity): DotEdge do
		var nfrom = draw_node(mentity)
		var dots = to_dots.get_or_null(mentity)
		if dots == null then
			dots = dotdotdot("...{nfrom.id}")
			from_dots[mentity] = dots
		end
		graph.add dots
		var edge = new DotEdge(dots, nfrom)
		graph.add edge
		return edge
	end

	# Change the border color of the node
	fun highlight(dot: DotElement): DotElement do
		dot["color"] = "#1E9431"
		return dot
	end

	# Generate a `...` node
	fun dotdotdot(id: String): DotNode do
		var node = new DotNode(id)
		node["label"] = "..."
		node["shape"] = "none"
		return node
	end
end
src/doc/commands/commands_graph.nit:175,1--358,3