Merge: Fix reading from Sockets
[nit.git] / src / doc / doc_phases / doc_concerns.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 # Concerns computation.
16 module doc_concerns
17
18 import doc_pages
19
20 # ConcernsPhase computes the ConcernsTree used for each page layout.
21 class ConcernsPhase
22 super DocPhase
23
24 # Populates the given DocModel.
25 redef fun apply do
26 for page in doc.pages.values do page.build_concerns(doc)
27 end
28 end
29
30 redef class DocPage
31
32 # Build the `concerns` tree for this page.
33 #
34 # Since only `MEntityPage`, this method is a no-op for everything else.
35 private fun build_concerns(doc: DocModel) do end
36 end
37
38 redef class MEntityPage
39
40 # Concerns to display in this page.
41 var concerns: nullable ConcernsTree = null
42 end
43
44 # TODO ConcernsTrees are a PITA, following redef should not be needed here...
45 # The bad, so baaaadddd, ConcernsTree interface induces a lot of useless code
46 # in all phases.
47
48 redef class MGroupPage
49
50 # Introduced classes in `mentity` that should appear in this page.
51 var intros = new HashSet[MClass]
52
53 # Refined classes in `mentity` that should appear in this page.
54 var redefs = new HashSet[MClass]
55
56 redef fun build_concerns(doc) do
57 var mmodules = new HashSet[MModule]
58 for mmodule in mentity.collect_mmodules do
59 if doc.mmodules.has(mmodule) then mmodules.add mmodule
60 # collect mclasses
61 for mclass in mmodule.intro_mclasses do
62 if doc.mclasses.has(mclass) then intros.add mclass
63 end
64 for mclass in mmodule.redef_mclasses do
65 if doc.mclasses.has(mclass) then redefs.add mclass
66 end
67 end
68 concerns = doc.model.concerns_tree(mmodules)
69 end
70 end
71
72 redef class MModulePage
73
74 # MClasses defined in `mentity` to display in this page.
75 var mclasses = new HashSet[MClass]
76
77 # MClassDefs located in `mentity` to display in this page.
78 var mclassdefs = new HashSet[MClassDef]
79
80 redef fun build_concerns(doc) do
81 # extract mclassdefs in mmodule
82 for mclassdef in mentity.mclassdefs do
83 if doc.mclassdefs.has(mclassdef) then mclassdefs.add mclassdef
84 end
85 # extract mclasses in mmodule
86 for mclassdef in mclassdefs do
87 var mclass = mclassdef.mclass
88 if doc.mclasses.has(mclass) then mclasses.add mclass
89 end
90 # extract concerns
91 var mods = new HashSet[MModule]
92 for mclass in mclasses do
93 var mod = mclass.intro_mmodule
94 if doc.mmodules.has(mod) then mods.add mod
95 end
96 concerns = doc.model.concerns_tree(mods)
97 end
98 end
99
100 redef class MClassPage
101
102 # MClassDefs to display in this page.
103 var mclassdefs = new HashSet[MClassDef]
104
105 # MPropdefs to display in this page.
106 var mpropdefs = new HashSet[MPropDef]
107
108 redef fun build_concerns(doc) do
109 # collect mclassdefs
110 for mclassdef in mentity.mclassdefs do
111 if doc.mclassdefs.has(mclassdef) then mclassdefs.add mclassdef
112 end
113 # collect mpropdefs
114 for mclassdef in mclassdefs do
115 for mpropdef in mclassdef.mpropdefs do
116 if doc.mpropdefs.has(mpropdef) then mpropdefs.add mpropdef
117 end
118 end
119 # collect concerns
120 var mods = new HashSet[MModule]
121 for mpropdef in mpropdefs do
122 var mod = mpropdef.mclassdef.mmodule
123 if doc.mmodules.has(mod) then mods.add mod
124 end
125 concerns = doc.model.concerns_tree(mods)
126 end
127 end
128
129 redef class MPropertyPage
130
131 # MPropdefs to display in this page.
132 var mpropdefs = new HashSet[MPropDef]
133
134 redef fun build_concerns(doc) do
135 # collect mpropdefs
136 for mpropdef in mentity.mpropdefs do
137 # FIXME diff hack
138 if mpropdef.is_intro then continue
139 if doc.mpropdefs.has(mpropdef) then mpropdefs.add mpropdef
140 end
141 # collect concerns
142 var mods = new HashSet[MModule]
143 for mpropdef in mpropdefs do
144 var mod = mpropdef.mclassdef.mmodule
145 if doc.mmodules.has(mod) then mods.add mod
146 end
147 concerns = doc.model.concerns_tree(mods)
148 end
149 end