# inheritance section
private fun tpl_inheritance(parent: TplSection) do
- # Extract relevent modules
- var imports = mmodule.in_importation.greaters
- if imports.length > 10 then imports = mmodule.in_importation.direct_greaters
- var clients = mmodule.in_importation.smallers
- if clients.length > 10 then clients = mmodule.in_importation.direct_smallers
-
# Display lists
var section = new TplSection.with_title("dependencies", "Dependencies")
# Imports
var lst = new Array[MModule]
- for dep in imports do
- if dep.is_fictive or dep.is_test_suite then continue
- if dep == mmodule then continue
- lst.add(dep)
- end
if not lst.is_empty then
name_sorter.sort lst
section.add_child tpl_list("imports", "Imports", lst)
# Clients
lst = new Array[MModule]
- for dep in clients do
- if dep.is_fictive or dep.is_test_suite then continue
- if dep == mmodule then continue
- lst.add(dep)
- end
if not lst.is_empty then
name_sorter.sort lst
section.add_child tpl_list("clients", "Clients", lst)
# Genrate dot hierarchy for class inheritance
fun tpl_dot(mmodules: Collection[MModule]): nullable TplArticle do
- var poset = new POSet[MModule]
- for mmodule in mmodules do
- if mmodule.is_fictive or mmodule.is_test_suite then continue
- poset.add_node mmodule
- for omodule in mmodules do
- if omodule.is_fictive or omodule.is_test_suite then continue
- poset.add_node mmodule
- if mmodule.in_importation < omodule then
- poset.add_edge(mmodule, omodule)
- end
- end
- end
# build graph
var op = new RopeBuffer
var name = "dep_module_{mmodule.nitdoc_id}"
end
private fun tpl_inheritance(parent: TplSection) do
- # parents
- var hparents = new HashSet[MClass]
- for c in mclass.in_hierarchy(mainmodule).direct_greaters do
- if ctx.filter_mclass(c) then hparents.add c
- end
-
- # ancestors
- var hancestors = new HashSet[MClass]
- for c in mclass.in_hierarchy(mainmodule).greaters do
- if c == mclass then continue
- if not ctx.filter_mclass(c) then continue
- if hparents.has(c) then continue
- hancestors.add c
- end
-
- # children
- var hchildren = new HashSet[MClass]
- for c in mclass.in_hierarchy(mainmodule).direct_smallers do
- if ctx.filter_mclass(c) then hchildren.add c
- end
-
- # descendants
- var hdescendants = new HashSet[MClass]
- for c in mclass.in_hierarchy(mainmodule).smallers do
- if c == mclass then continue
- if not ctx.filter_mclass(c) then continue
- if hchildren.has(c) then continue
- hdescendants.add c
- end
-
# Display lists
var section = new TplSection.with_title("inheritance", "Inheritance")
# Generate dot hierarchy for classes
fun tpl_dot(mclasses: Collection[MClass]): nullable TplArticle do
- var poset = new POSet[MClass]
-
- for mclass in mclasses do
- poset.add_node mclass
- for oclass in mclasses do
- if mclass == oclass then continue
- poset.add_node oclass
- if mclass.in_hierarchy(mainmodule) < oclass then
- poset.add_edge(mclass, oclass)
- end
- end
- end
-
var op = new RopeBuffer
var name = "dep_class_{mclass.nitdoc_id}"
op.append("digraph \"{name.escape_to_dot}\" \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Importation and inheritance POSet for pages.
+module doc_poset
+
+import doc_pages
+
+# This phase computes importation and inheritance POSet for pages.
+class POSetPhase
+ super DocPhase
+
+ # Populates the given DocModel.
+ redef fun apply do
+ for page in doc.pages do
+ if page isa MEntityPage then page.build_poset(self, doc)
+ end
+ end
+end
+
+redef class MEntityPage
+
+ # The poset associated with this page.
+ #
+ # FIXME should be defined in subclasses
+ # as the POSet can contains other types than `SELF`
+ var poset = new POSet[MENTITY]
+
+ # Build the POSet for this page.
+ private fun build_poset(v: POSetPhase, doc: DocModel) do end
+end
+
+redef class MModulePage
+
+ # Imported modules that should appear in the documentation.
+ var imports = new HashSet[MModule]
+
+ # Clients modules that shjould appear in the documentation.
+ var clients = new HashSet[MModule]
+
+ redef fun build_poset(v, doc) do
+ # collect importation
+ for dep in mentity.in_importation.greaters do
+ if dep == mentity then continue
+ if not doc.mmodules.has(dep) then continue
+ imports.add dep
+ end
+ # FIXME avoid diff
+ #if imports.length > 10 then
+ if mentity.in_importation.greaters.length > 10 then
+ imports.clear
+ for dep in mentity.in_importation.direct_greaters do
+ if dep == mentity then continue
+ if not doc.mmodules.has(dep) then continue
+ imports.add dep
+ end
+ end
+ # collect clients
+ for dep in mentity.in_importation.smallers do
+ if dep == mentity then continue
+ if not doc.mmodules.has(dep) then continue
+ clients.add dep
+ end
+ if clients.length > 10 then
+ clients.clear
+ for dep in mentity.in_importation.direct_smallers do
+ if dep == mentity then continue
+ if not doc.mmodules.has(dep) then continue
+ clients.add dep
+ end
+ end
+ # make poset
+ var mmodules = new HashSet[MModule]
+ mmodules.add_all mentity.nested_mmodules
+ mmodules.add_all imports
+ if clients.length < 10 then mmodules.add_all clients
+ mmodules.add mentity
+ build_importation_poset(doc, mmodules)
+ end
+
+ # Build the POSet of importation from a list of `mmodules`.
+ private fun build_importation_poset(doc: DocModel, mmodules: Set[MModule]): POSet[MModule] do
+ for mmodule in mmodules do
+ if not doc.mmodules.has(mmodule) then continue
+ poset.add_node mmodule
+ for omodule in mmodules do
+ if not doc.mmodules.has(omodule) then continue
+ poset.add_node mmodule
+ if mmodule.in_importation < omodule then
+ poset.add_edge(mmodule, omodule)
+ end
+ end
+ end
+ return poset
+ end
+end
+
+redef class MClassPage
+
+ # Direct parents classes to document.
+ var parents = new HashSet[MClass]
+
+ # Transitive ancestors classes to document.
+ #
+ # Does not contain the direct ancestors.
+ # See `parents` for that.
+ var ancestors = new HashSet[MClass]
+
+ # Direct children classes to document.
+ var children = new HashSet[MClass]
+
+ # All descendants classes to document.
+ #
+ # Does not contain the direct children.
+ # See `children` for that.
+ var descendants = new HashSet[MClass]
+
+ redef fun build_poset(v, doc) do
+ poset.add_node mentity
+
+ var h = mentity.in_hierarchy(doc.mainmodule)
+ # parents
+ for mclass in h.direct_greaters do
+ if doc.mclasses.has(mclass) then parents.add mclass
+ end
+ # ancestors
+ for mclass in h.greaters do
+ if mclass == mentity then continue
+ if not doc.mclasses.has(mclass) then continue
+ if parents.has(mclass) then continue
+ ancestors.add mclass
+ end
+ # children
+ for mclass in h.direct_smallers do
+ if doc.mclasses.has(mclass) then children.add mclass
+ end
+ # descendants
+ for mclass in h.smallers do
+ if mclass == mentity then continue
+ if not doc.mclasses.has(mclass) then continue
+ if children.has(mclass) then continue
+ descendants.add mclass
+ end
+ # poset
+ var mclasses = new HashSet[MClass]
+ mclasses.add_all ancestors
+ mclasses.add_all parents
+ mclasses.add_all children
+ mclasses.add_all descendants
+ mclasses.add mentity
+ build_inheritance_poset(v, doc, mclasses)
+ end
+
+ private fun build_inheritance_poset(v: POSetPhase, doc: DocModel, mclasses: Set[MClass]): POSet[MClass] do
+ for mclass in mclasses do
+ poset.add_node mclass
+ for oclass in mclasses do
+ if mclass == oclass then continue
+ poset.add_node oclass
+ if mclass.in_hierarchy(doc.mainmodule) < oclass then
+ poset.add_edge(mclass, oclass)
+ end
+ end
+ end
+ return poset
+ end
+end