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 # Add linearization lists to DefinitionArticle found in MClass pages.
20 # LinPhase populates the DocPage content with linearization data.
24 # Used to sort list by linearization order
25 private var lin_sorter
= new MEntityNameSorter
28 for page
in doc
.pages
.values
do page
.apply_linearization
(self, doc
)
34 # Populates `self` with linearization data.
37 fun apply_linearization
(v
: LinListPhase, doc
: DocModel) do end
40 redef class MClassPage
41 redef fun apply_linearization
(v
, doc
) do
42 root
.apply_linearization
(v
, doc
, self)
46 redef class DocComposite
48 # Populates `self` with linearization data.
50 # For now, it's only used for mpropdefs linearization in MClassPage.
53 private fun apply_linearization
(v
: LinListPhase, doc
: DocModel, page
: DocPage) do
54 for child
in children
do child
.apply_linearization
(v
, doc
, page
)
58 redef class DefinitionArticle
59 redef fun apply_linearization
(v
, doc
, page
) do
60 var mentity
= self.mentity
61 if not mentity
isa MPropDef then return
63 var all_defs
= new HashSet[MPropDef]
64 for local_def
in local_defs
(page
.as(MClassPage), mentity
.mproperty
) do
65 all_defs
.add local_def
66 var smpropdef
= local_def
67 while not smpropdef
.is_intro
do
68 smpropdef
= smpropdef
.lookup_next_definition
(
69 doc
.mainmodule
, smpropdef
.mclassdef
.bound_mtype
)
70 all_defs
.add smpropdef
73 var lin
= all_defs
.to_a
74 doc
.mainmodule
.linearize_mpropdefs
(lin
)
75 if lin
.length
> 1 then
76 add_child
new DefinitionLinArticle("{mentity.nitdoc_id}.lin", "Linearization", lin
)
80 # Filter `page.mpropdefs` for this `mpropertie`.
82 # FIXME compatability with current templates.
83 private fun local_defs
(page
: MClassPage, mproperty
: MProperty): HashSet[MPropDef] do
84 var mpropdefs
= new HashSet[MPropDef]
85 for mpropdef
in page
.mpropdefs
do
86 if mpropdef
.mproperty
== mproperty
then
87 mpropdefs
.add mpropdef
94 # Display a linearized list of definitions.
95 class DefinitionLinArticle
98 # The linearized list to display.
99 var mentities
: Array[MEntity]
101 redef fun is_hidden
do return mentities
.is_empty
102 redef var is_toc_hidden
= true