Merge: Introduce Cloneable interface
[nit.git] / src / doc / doc_phases / doc_intros_redefs.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 # Generates lists about intros/redefs in MEntity.
16 #
17 # Actually, this works only for MModules and MclassDefs.
18 module doc_intros_redefs
19
20 import doc_structure
21
22 # Computes intro / redef mentity list for each DefinitionArticle.
23 class IntroRedefListPhase
24 super DocPhase
25
26 redef fun apply do
27 for page in doc.pages do
28 if not page isa MEntityPage then continue
29 page.root.build_intro_redef_list(self, doc, page)
30 end
31 end
32 end
33
34 redef class DocComposite
35
36 # Computes intro / redef lists for this page.
37 #
38 # See `IntroRedefListPhase`.
39 fun build_intro_redef_list(v: IntroRedefListPhase, doc: DocModel, page: MEntityPage) do
40 for child in children do child.build_intro_redef_list(v, doc, page)
41 end
42 end
43
44 redef class DefinitionArticle
45 redef fun build_intro_redef_list(v, doc, page) do
46 var mentity = self.mentity
47 if mentity isa MModule then
48 build_mmodule_list(v, doc, mentity)
49 else if mentity isa MClassDef and mentity.mmodule == page.mentity then
50 build_mclassdef_list(v, doc, mentity)
51 end
52 super
53 end
54
55 # TODO this should move to MEntity?
56 private fun build_mmodule_list(v: IntroRedefListPhase, doc: DocModel, mmodule: MModule) do
57 var intros = mmodule.intro_mclassdefs(v.ctx.min_visibility).to_a
58 doc.mainmodule.linearize_mclassdefs(intros)
59 add_child new IntrosRedefsListArticle(mentity, "Introduces", intros)
60 var redefs = mmodule.redef_mclassdefs(v.ctx.min_visibility).to_a
61 doc.mainmodule.linearize_mclassdefs(redefs)
62 add_child new IntrosRedefsListArticle(mentity, "Redefines", redefs)
63 end
64
65 # TODO this should move to MEntity?
66 private fun build_mclassdef_list(v: IntroRedefListPhase, doc: DocModel, mclassdef: MClassDef) do
67 var intros = mclassdef.collect_intro_mpropdefs(v.ctx.min_visibility).to_a
68 # FIXME avoid diff changes
69 # v.ctx.mainmodule.linearize_mpropdefs(intros)
70 add_child new IntrosRedefsListArticle(mentity, "Introduces", intros)
71 var redefs = mclassdef.collect_redef_mpropdefs(v.ctx.min_visibility).to_a
72 # FIXME avoid diff changes
73 # v.ctx.mainmodule.linearize_mpropdefs(redefs)
74 add_child new IntrosRedefsListArticle(mentity, "Redefines", redefs)
75 end
76
77 end
78
79 # An article that displays a list of introduced / refined mentities.
80 #
81 # FIXME diff hack
82 # This can merged with InheritanceListArticle in a more generic class.
83 class IntrosRedefsListArticle
84 super MEntityArticle
85
86 # Title displayed as header of the list.
87 var list_title: String
88
89 # Intro mentities to list.
90 var mentities: Array[MEntity]
91 end