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 # Importation and inheritance POSet for pages.
19 import model
::model_collect
21 # This phase computes importation and inheritance POSet for pages.
25 # Populates the given DocModel.
27 for page
in doc
.pages
.values
do
28 if page
isa MEntityPage then page
.build_poset
(self, doc
)
33 redef class MEntityPage
35 # The poset associated with this page.
37 # FIXME should be defined in subclasses
38 # as the POSet can contains other types than `SELF`
39 var poset
= new POSet[MENTITY]
41 # Build the POSet for this page.
42 private fun build_poset
(v
: POSetPhase, doc
: DocModel) do end
45 redef class MModulePage
47 # Imported modules that should appear in the documentation.
48 var imports
= new HashSet[MModule]
50 # Clients modules that should appear in the documentation.
51 var clients
= new HashSet[MModule]
53 redef fun build_poset
(v
, doc
) do
55 for dep
in mentity
.in_importation
.greaters
do
56 if dep
== mentity
then continue
57 if not doc
.mmodules
.has
(dep
) then continue
61 #if imports.length > 10 then
62 if mentity
.in_importation
.greaters
.length
> 10 then
64 for dep
in mentity
.in_importation
.direct_greaters
do
65 if dep
== mentity
then continue
66 if not doc
.mmodules
.has
(dep
) then continue
71 for dep
in mentity
.in_importation
.smallers
do
72 if dep
== mentity
then continue
73 if not doc
.mmodules
.has
(dep
) then continue
76 if clients
.length
> 10 then
78 for dep
in mentity
.in_importation
.direct_smallers
do
79 if dep
== mentity
then continue
80 if not doc
.mmodules
.has
(dep
) then continue
85 var mmodules
= new HashSet[MModule]
86 var mgroup
= mentity
.mgroup
87 if mgroup
!= null and mgroup
.default_mmodule
== mentity
then
88 mmodules
.add_all mgroup
.mmodules
90 mmodules
.add_all imports
91 if clients
.length
< 10 then mmodules
.add_all clients
93 build_importation_poset
(doc
, mmodules
)
96 # Build the POSet of importation from a list of `mmodules`.
97 private fun build_importation_poset
(doc
: DocModel, mmodules
: Set[MModule]): POSet[MModule] do
98 for mmodule
in mmodules
do
99 if not doc
.mmodules
.has
(mmodule
) then continue
100 poset
.add_node mmodule
101 for omodule
in mmodules
do
102 if not doc
.mmodules
.has
(omodule
) then continue
103 poset
.add_node mmodule
104 if mmodule
.in_importation
< omodule
then
105 poset
.add_edge
(mmodule
, omodule
)
113 redef class MClassPage
115 # Direct parents classes to document.
116 var parents
= new HashSet[MClass]
118 # Transitive ancestors classes to document.
120 # Does not contain the direct ancestors.
121 # See `parents` for that.
122 var ancestors
= new HashSet[MClass]
124 # Direct children classes to document.
125 var children
= new HashSet[MClass]
127 # All descendants classes to document.
129 # Does not contain the direct children.
130 # See `children` for that.
131 var descendants
= new HashSet[MClass]
133 redef fun build_poset
(v
, doc
) do
134 poset
.add_node mentity
136 var h
= mentity
.in_hierarchy
(doc
.mainmodule
)
138 for mclass
in h
.direct_greaters
do
139 if doc
.mclasses
.has
(mclass
) then parents
.add mclass
142 for mclass
in h
.greaters
do
143 if mclass
== mentity
then continue
144 if not doc
.mclasses
.has
(mclass
) then continue
145 if parents
.has
(mclass
) then continue
149 for mclass
in h
.direct_smallers
do
150 if doc
.mclasses
.has
(mclass
) then children
.add mclass
153 for mclass
in h
.smallers
do
154 if mclass
== mentity
then continue
155 if not doc
.mclasses
.has
(mclass
) then continue
156 if children
.has
(mclass
) then continue
157 descendants
.add mclass
160 var mclasses
= new HashSet[MClass]
161 mclasses
.add_all ancestors
162 mclasses
.add_all parents
163 mclasses
.add_all children
164 mclasses
.add_all descendants
166 build_inheritance_poset
(v
, doc
, mclasses
)
169 private fun build_inheritance_poset
(v
: POSetPhase, doc
: DocModel, mclasses
: Set[MClass]): POSet[MClass] do
170 for mclass
in mclasses
do
171 poset
.add_node mclass
172 for oclass
in mclasses
do
173 if mclass
== oclass
then continue
174 poset
.add_node oclass
175 if mclass
.in_hierarchy
(doc
.mainmodule
) < oclass
then
176 poset
.add_edge
(mclass
, oclass
)