1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Computes importation and class hierarchy lists.
16 module doc_hierarchies
21 # Insert inheritance / importation lists in the page.
22 class InheritanceListsPhase
25 # Used to sort list by name.
26 var name_sorter
= new MEntityNameSorter
29 for page
in doc
.pages
do
30 if page
isa MEntityPage then page
.build_inh_list
(self, doc
)
35 redef class MEntityPage
37 # Build importation / inheritance list for this page.
38 fun build_inh_list
(v
: InheritanceListsPhase, doc
: DocModel) do end
41 redef class MModulePage
42 redef fun build_inh_list
(v
, doc
) do
43 var section
= new ImportationListSection(mentity
)
44 var group
= new PanelGroup("List")
45 var imports
= self.imports
.to_a
46 v
.name_sorter
.sort
(imports
)
47 group
.add_child
new HierarchyListArticle(mentity
, "Imports", imports
)
48 var clients
= self.clients
.to_a
49 v
.name_sorter
.sort
(clients
)
50 group
.add_child
new HierarchyListArticle(mentity
, "Clients", clients
)
51 section
.add_child group
52 section
.parent
= root
.children
.first
53 root
.children
.first
.children
.insert
(section
, 1)
57 redef class MClassPage
58 redef fun build_inh_list
(v
, doc
) do
59 var section
= new InheritanceListSection(mentity
)
60 var group
= new PanelGroup("List")
61 var parents
= self.parents
.to_a
62 v
.name_sorter
.sort
(parents
)
63 group
.add_child
new HierarchyListArticle(mentity
, "Parents", parents
)
64 var ancestors
= self.ancestors
.to_a
65 v
.name_sorter
.sort
(ancestors
)
66 group
.add_child
new HierarchyListArticle(mentity
, "Ancestors", ancestors
)
67 var children
= self.children
.to_a
68 v
.name_sorter
.sort
(children
)
69 group
.add_child
new HierarchyListArticle(mentity
, "Children", children
)
70 var descendants
= self.descendants
.to_a
71 v
.name_sorter
.sort
(descendants
)
72 group
.add_child
new HierarchyListArticle(mentity
, "Descendants", descendants
)
73 section
.add_child group
74 section
.parent
= root
.children
.first
75 root
.children
.first
.children
.insert
(section
, 1)
80 class ImportationListSection
82 super MEntityComposite
86 class InheritanceListSection
88 super MEntityComposite
91 # Dislay a hierarchical list of mentities.
92 class HierarchyListArticle
95 # Title displayed in the top of this list.
96 var list_title
: String
98 # MEntities to display in this list.
99 var mentities
: Array[MEntity]