private var mgroup: MGroup
- private var concerns: ConcernsTree is noinit
- private var intros: Set[MClass] is noinit
- private var redefs: Set[MClass] is noinit
-
- init do
- self.concerns = model.concerns_tree(mgroup.collect_mmodules)
- self.concerns.sort_with(new MConcernRankSorter)
- self.intros = mgroup.in_nesting_intro_mclasses(ctx.min_visibility)
- var redefs = new HashSet[MClass]
- for rdef in mgroup.in_nesting_redef_mclasses(ctx.min_visibility) do
- if intros.has(rdef) then continue
- redefs.add rdef
- end
- self.redefs = redefs
- end
-
private var page = new TplPage
redef fun tpl_page do return page
tpl_groups(top)
tpl_page.add_section top
end
-
- private fun sort_by_mclass(mclassdefs: Collection[MClassDef]): Map[MClass, Set[MClassDef]] do
- var map = new HashMap[MClass, Set[MClassDef]]
- for mclassdef in mclassdefs do
- var mclass = mclassdef.mclass
- if not map.has_key(mclass) then map[mclass] = new HashSet[MClassDef]
- map[mclass].add mclassdef
- end
- return map
- end
end
# A module page
super NitdocPage
private var mmodule: MModule
- private var concerns: ConcernsTree is noinit
- private var mclasses2mdefs: Map[MClass, Set[MClassDef]] is noinit
- private var mmodules2mclasses: Map[MModule, Set[MClass]] is noinit
-
-
- init do
- var mclassdefs = new HashSet[MClassDef]
- mclassdefs.add_all mmodule.intro_mclassdefs(ctx.min_visibility)
- mclassdefs.add_all mmodule.redef_mclassdefs(ctx.min_visibility)
- self.mclasses2mdefs = sort_by_mclass(mclassdefs)
- self.mmodules2mclasses = group_by_mmodule(mclasses2mdefs.keys)
- self.concerns = model.concerns_tree(mmodules2mclasses.keys)
- # rank concerns
- mmodule.mgroup.mproject.booster_rank = -1000
- mmodule.mgroup.booster_rank = -1000
- mmodule.booster_rank = -1000
- self.concerns.sort_with(new MConcernRankSorter)
- mmodule.mgroup.mproject.booster_rank = 0
- mmodule.mgroup.booster_rank = 0
- mmodule.booster_rank = 0
- end
private var page = new TplPage
redef fun tpl_page do return page
end
end
- private fun group_by_mmodule(mclasses: Collection[MClass]): Map[MModule, Set[MClass]] do
- var res = new HashMap[MModule, Set[MClass]]
- for mclass in mclasses do
- var mmodule = mclass.intro_mmodule
- if not res.has_key(mmodule) then
- res[mmodule] = new HashSet[MClass]
- end
- res[mmodule].add(mclass)
- end
- return res
- end
-
redef fun tpl_content do
tpl_sidebar_mclasses
var top = tpl_intro
op.append("\}\n")
return tpl_graph(op, name, null)
end
-
- private fun sort_by_mclass(mclassdefs: Collection[MClassDef]): Map[MClass, Set[MClassDef]] do
- var map = new HashMap[MClass, Set[MClassDef]]
- for mclassdef in mclassdefs do
- var mclass = mclassdef.mclass
- if not map.has_key(mclass) then map[mclass] = new HashSet[MClassDef]
- map[mclass].add mclassdef
- end
- return map
- end
end
# A class page
super NitdocPage
private var mclass: MClass
- private var concerns: ConcernsTree is noinit
- private var mprops2mdefs: Map[MProperty, Set[MPropDef]] is noinit
- private var mmodules2mprops: Map[MModule, Set[MProperty]] is noinit
-
- init do
- var mpropdefs = new HashSet[MPropDef]
- mpropdefs.add_all mclass.intro_mpropdefs(ctx.min_visibility)
- mpropdefs.add_all mclass.redef_mpropdefs(ctx.min_visibility)
- self.mprops2mdefs = sort_by_mproperty(mpropdefs)
- self.mmodules2mprops = sort_by_mmodule(mprops2mdefs.keys)
- self.concerns = model.concerns_tree(mmodules2mprops.keys)
- self.concerns.sort_with(new MConcernRankSorter)
- end
private var page = new TplPage
redef fun tpl_page do return page
tpl_page.add_section top
end
- private fun sort_by_mproperty(mpropdefs: Collection[MPropDef]): Map[MProperty, Set[MPropDef]] do
- var map = new HashMap[MProperty, Set[MPropDef]]
- for mpropdef in mpropdefs do
- var mproperty = mpropdef.mproperty
- if not map.has_key(mproperty) then map[mproperty] = new HashSet[MPropDef]
- map[mproperty].add mpropdef
- end
- return map
- end
-
- private fun sort_by_mmodule(mprops: Collection[MProperty]): Map[MModule, Set[MProperty]] do
- var map = new HashMap[MModule, Set[MProperty]]
- for mprop in mprops do
- var mpropdefs = mprops2mdefs[mprop].to_a
- mainmodule.linearize_mpropdefs(mpropdefs)
- var mmodule = mpropdefs.first.mclassdef.mmodule
- if not map.has_key(mmodule) then map[mmodule] = new HashSet[MProperty]
- map[mmodule].add mprop
- end
- return map
- end
-
private fun mclass_inherited_mprops: Set[MProperty] do
var res = new HashSet[MProperty]
var local = mclass.local_mproperties(ctx.min_visibility)
return res
end
- private fun collect_mmodules(mprops: Collection[MProperty]): Set[MModule] do
- var res = new HashSet[MModule]
- for mprop in mprops do
- if mprops2mdefs.has_key(mprop) then
- for mpropdef in mprops2mdefs[mprop] do res.add mpropdef.mclassdef.mmodule
- end
- end
- return res
- end
-
# Generate dot hierarchy for classes
fun tpl_dot(mclasses: Collection[MClass]): nullable TplArticle do
var poset = new POSet[MClass]
super NitdocPage
private var mproperty: MProperty
- private var concerns: ConcernsTree is noinit
- private var mmodules2mdefs: Map[MModule, Set[MPropDef]] is noinit
-
- init do
- self.mproperty = mproperty
- self.mmodules2mdefs = sort_by_mmodule(collect_mpropdefs)
- self.concerns = model.concerns_tree(mmodules2mdefs.keys)
- self.concerns.sort_with(new MConcernRankSorter)
- end
-
- private fun collect_mpropdefs: Set[MPropDef] do
- var res = new HashSet[MPropDef]
- for mpropdef in mproperty.mpropdefs do
- if not mpropdef.is_intro then res.add mpropdef
- end
- return res
- end
private var page = new TplPage
redef fun tpl_page do return page
tpl_properties(top)
tpl_page.add_section top
end
-
- private fun sort_by_mmodule(mpropdefs: Collection[MPropDef]): Map[MModule, Set[MPropDef]] do
- var map = new HashMap[MModule, Set[MPropDef]]
- for mpropdef in mpropdefs do
- var mmodule = mpropdef.mclassdef.mmodule
- if not map.has_key(mmodule) then map[mmodule] = new HashSet[MPropDef]
- map[mmodule].add mpropdef
- end
- return map
- end
end
--- /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.
+
+# Concerns computation.
+module doc_concerns
+
+import doc_pages
+
+# ConcernsPhase computes the ConcernsTree used for each page layout.
+class ConcernsPhase
+ super DocPhase
+
+ # Populates the given DocModel.
+ redef fun apply do
+ for page in doc.pages do page.build_concerns(doc)
+ end
+end
+
+redef class DocPage
+
+ # Build the `concerns` tree for this page.
+ #
+ # Since only `MEntityPage`, this method is a no-op for everything else.
+ private fun build_concerns(doc: DocModel) do end
+end
+
+redef class MEntityPage
+
+ # Concerns to display in this page.
+ var concerns: nullable ConcernsTree = null
+end
+
+# TODO ConcernsTrees are a PITA, following redef should not be needed here...
+# The bad, so baaaadddd, ConcernsTree interface induces a lot of useless code
+# in all phases.
+
+redef class MGroupPage
+
+ # Introduced classes in `mentity` that should appear in this page.
+ var intros = new HashSet[MClass]
+
+ # Refined classes in `mentity` that should appear in this page.
+ var redefs = new HashSet[MClass]
+
+ redef fun build_concerns(doc) do
+ var mmodules = new HashSet[MModule]
+ for mmodule in mentity.collect_mmodules do
+ if doc.mmodules.has(mmodule) then mmodules.add mmodule
+ # collect mclasses
+ for mclass in mmodule.intro_mclasses do
+ if doc.mclasses.has(mclass) then intros.add mclass
+ end
+ for mclass in mmodule.redef_mclasses do
+ if doc.mclasses.has(mclass) then redefs.add mclass
+ end
+ end
+ concerns = doc.model.concerns_tree(mmodules)
+ end
+end
+
+redef class MModulePage
+
+ # MClasses defined in `mentity` to display in this page.
+ var mclasses = new HashSet[MClass]
+
+ # MClassDefs located in `mentity` to display in this page.
+ var mclassdefs = new HashSet[MClassDef]
+
+ redef fun build_concerns(doc) do
+ # extract mclassdefs in mmodule
+ for mclassdef in mentity.mclassdefs do
+ if doc.mclassdefs.has(mclassdef) then mclassdefs.add mclassdef
+ end
+ # extract mclasses in mmodule
+ for mclassdef in mclassdefs do
+ var mclass = mclassdef.mclass
+ if doc.mclasses.has(mclass) then mclasses.add mclass
+ end
+ # extract concerns
+ var mods = new HashSet[MModule]
+ for mclass in mclasses do
+ var mod = mclass.intro_mmodule
+ if doc.mmodules.has(mod) then mods.add mod
+ end
+ concerns = doc.model.concerns_tree(mods)
+ end
+end
+
+redef class MClassPage
+
+ # MClassDefs to display in this page.
+ var mclassdefs = new HashSet[MClassDef]
+
+ # MPropdefs to display in this page.
+ var mpropdefs = new HashSet[MPropDef]
+
+ redef fun build_concerns(doc) do
+ # collect mclassdefs
+ for mclassdef in mentity.mclassdefs do
+ if doc.mclassdefs.has(mclassdef) then mclassdefs.add mclassdef
+ end
+ # collect mpropdefs
+ for mclassdef in mclassdefs do
+ for mpropdef in mclassdef.mpropdefs do
+ if doc.mpropdefs.has(mpropdef) then mpropdefs.add mpropdef
+ end
+ end
+ # collect concerns
+ var mods = new HashSet[MModule]
+ for mpropdef in mpropdefs do
+ var mod = mpropdef.mclassdef.mmodule
+ if doc.mmodules.has(mod) then mods.add mod
+ end
+ concerns = doc.model.concerns_tree(mods)
+ end
+end
+
+redef class MPropertyPage
+
+ # MPropdefs to display in this page.
+ var mpropdefs = new HashSet[MPropDef]
+
+ redef fun build_concerns(doc) do
+ # collect mpropdefs
+ for mpropdef in mentity.mpropdefs do
+ # FIXME diff hack
+ if mpropdef.is_intro then continue
+ if doc.mpropdefs.has(mpropdef) then mpropdefs.add mpropdef
+ end
+ # collect concerns
+ var mods = new HashSet[MModule]
+ for mpropdef in mpropdefs do
+ var mod = mpropdef.mclassdef.mmodule
+ if doc.mmodules.has(mod) then mods.add mod
+ end
+ concerns = doc.model.concerns_tree(mods)
+ end
+end