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.
20 # This phase computes importation and inheritance POSet for pages.
24 # Populates the given DocModel.
26 for page
in doc
.pages
do
27 if page
isa MEntityPage then page
.build_poset
(self, doc
)
32 redef class MEntityPage
34 # The poset associated with this page.
36 # FIXME should be defined in subclasses
37 # as the POSet can contains other types than `SELF`
38 var poset
= new POSet[MENTITY]
40 # Build the POSet for this page.
41 private fun build_poset
(v
: POSetPhase, doc
: DocModel) do end
44 redef class MModulePage
46 # Imported modules that should appear in the documentation.
47 var imports
= new HashSet[MModule]
49 # Clients modules that shjould appear in the documentation.
50 var clients
= new HashSet[MModule]
52 redef fun build_poset
(v
, doc
) do
54 for dep
in mentity
.in_importation
.greaters
do
55 if dep
== mentity
then continue
56 if not doc
.mmodules
.has
(dep
) then continue
60 #if imports.length > 10 then
61 if mentity
.in_importation
.greaters
.length
> 10 then
63 for dep
in mentity
.in_importation
.direct_greaters
do
64 if dep
== mentity
then continue
65 if not doc
.mmodules
.has
(dep
) then continue
70 for dep
in mentity
.in_importation
.smallers
do
71 if dep
== mentity
then continue
72 if not doc
.mmodules
.has
(dep
) then continue
75 if clients
.length
> 10 then
77 for dep
in mentity
.in_importation
.direct_smallers
do
78 if dep
== mentity
then continue
79 if not doc
.mmodules
.has
(dep
) then continue
84 var mmodules
= new HashSet[MModule]
85 mmodules
.add_all mentity
.nested_mmodules
86 mmodules
.add_all imports
87 if clients
.length
< 10 then mmodules
.add_all clients
89 build_importation_poset
(doc
, mmodules
)
92 # Build the POSet of importation from a list of `mmodules`.
93 private fun build_importation_poset
(doc
: DocModel, mmodules
: Set[MModule]): POSet[MModule] do
94 for mmodule
in mmodules
do
95 if not doc
.mmodules
.has
(mmodule
) then continue
96 poset
.add_node mmodule
97 for omodule
in mmodules
do
98 if not doc
.mmodules
.has
(omodule
) then continue
99 poset
.add_node mmodule
100 if mmodule
.in_importation
< omodule
then
101 poset
.add_edge
(mmodule
, omodule
)
109 redef class MClassPage
111 # Direct parents classes to document.
112 var parents
= new HashSet[MClass]
114 # Transitive ancestors classes to document.
116 # Does not contain the direct ancestors.
117 # See `parents` for that.
118 var ancestors
= new HashSet[MClass]
120 # Direct children classes to document.
121 var children
= new HashSet[MClass]
123 # All descendants classes to document.
125 # Does not contain the direct children.
126 # See `children` for that.
127 var descendants
= new HashSet[MClass]
129 redef fun build_poset
(v
, doc
) do
130 poset
.add_node mentity
132 var h
= mentity
.in_hierarchy
(doc
.mainmodule
)
134 for mclass
in h
.direct_greaters
do
135 if doc
.mclasses
.has
(mclass
) then parents
.add mclass
138 for mclass
in h
.greaters
do
139 if mclass
== mentity
then continue
140 if not doc
.mclasses
.has
(mclass
) then continue
141 if parents
.has
(mclass
) then continue
145 for mclass
in h
.direct_smallers
do
146 if doc
.mclasses
.has
(mclass
) then children
.add mclass
149 for mclass
in h
.smallers
do
150 if mclass
== mentity
then continue
151 if not doc
.mclasses
.has
(mclass
) then continue
152 if children
.has
(mclass
) then continue
153 descendants
.add mclass
156 var mclasses
= new HashSet[MClass]
157 mclasses
.add_all ancestors
158 mclasses
.add_all parents
159 mclasses
.add_all children
160 mclasses
.add_all descendants
162 build_inheritance_poset
(v
, doc
, mclasses
)
165 private fun build_inheritance_poset
(v
: POSetPhase, doc
: DocModel, mclasses
: Set[MClass]): POSet[MClass] do
166 for mclass
in mclasses
do
167 poset
.add_node mclass
168 for oclass
in mclasses
do
169 if mclass
== oclass
then continue
170 poset
.add_node oclass
171 if mclass
.in_hierarchy
(doc
.mainmodule
) < oclass
then
172 poset
.add_edge
(mclass
, oclass
)