1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2008 Jean Privat <jean@pryen.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Collect things from a `Model`.
21 # `model_collect` offers a flattened view of the model without considering any
23 # For this reason, `model_collect` lists all the definitions reachable from all
26 # This is usefull for tools that need a global view of a model like `nitdoc`,
28 # It shoul not be used for compiling stuffs like computing VFT, where the listed
29 # entities could not be reachable depending on the modules really imported.
36 # Collect mclassdefs introduced in `self` with `visibility >= to min_visibility`.
37 fun collect_intro_mclassdefs
(view
: ModelView): Set[MClassDef] do
38 var res
= new HashSet[MClassDef]
39 for mclassdef
in mclassdefs
do
40 if not mclassdef
.is_intro
then continue
41 if not view
.accept_mentity
(mclassdef
) then continue
47 # Collect mclassdefs redefined in `self` with `visibility >= to min_visibility`.
48 fun collect_redef_mclassdefs
(view
: ModelView): Set[MClassDef] do
49 var res
= new HashSet[MClassDef]
50 for mclassdef
in mclassdefs
do
51 if mclassdef
.is_intro
then continue
52 if not view
.accept_mentity
(mclassdef
) then continue
58 # Collect mclasses introduced in `self` with `visibility >= to min_visibility`.
59 fun collect_intro_mclasses
(view
: ModelView): Set[MClass] do
60 var res
= new HashSet[MClass]
61 for mclass
in intro_mclasses
do
62 if not view
.accept_mentity
(mclass
) then continue
68 # Collect mclasses redefined in `self` with `visibility >= to min_visibility`.
69 fun collect_redef_mclasses
(view
: ModelView): Set[MClass] do
70 var mclasses
= new HashSet[MClass]
71 for mclassdef
in mclassdefs
do
72 if not view
.accept_mentity
(mclassdef
) then continue
73 if not mclassdef
.is_intro
then mclasses
.add
(mclassdef
.mclass
)
81 # Collect direct parents of `self` with `visibility >= to min_visibility`.
82 fun collect_parents
(view
: ModelView): Set[MClass] do
83 var res
= new HashSet[MClass]
84 for mclassdef
in mclassdefs
do
85 for mclasstype
in mclassdef
.supertypes
do
86 var mclass
= mclasstype
.mclass
87 if not view
.accept_mentity
(mclass
) then continue
94 # Collect all ancestors of `self` with `visibility >= to min_visibility`.
95 fun collect_ancestors
(view
: ModelView): Set[MClass] do
96 var res
= new HashSet[MClass]
97 for mclassdef
in self.mclassdefs
do
98 for super_mclassdef
in mclassdef
.in_hierarchy
.greaters
do
99 if super_mclassdef
== mclassdef
then continue # skip self
100 var mclass
= super_mclassdef
.mclass
101 if not view
.accept_mentity
(mclass
) then continue
108 # Collect direct children of `self` with `visibility >= to min_visibility`.
109 fun collect_children
(view
: ModelView): Set[MClass] do
110 var res
= new HashSet[MClass]
111 for mclassdef
in self.mclassdefs
do
112 for sub_mclassdef
in mclassdef
.in_hierarchy
.direct_smallers
do
113 if sub_mclassdef
== mclassdef
then continue # skip self
114 var mclass
= sub_mclassdef
.mclass
115 if not view
.accept_mentity
(mclass
) then continue
122 # Collect all descendants of `self` with `visibility >= to min_visibility`.
123 fun collect_descendants
(view
: ModelView): Set[MClass] do
124 var res
= new HashSet[MClass]
125 for mclassdef
in self.mclassdefs
do
126 for sub_mclassdef
in mclassdef
.in_hierarchy
.smallers
do
127 if sub_mclassdef
== mclassdef
then continue # skip self
128 var mclass
= sub_mclassdef
.mclass
129 if not view
.accept_mentity
(mclass
) then continue
136 # Collect all mproperties introduced in 'self' with `visibility >= min_visibility`.
137 fun collect_intro_mproperties
(view
: ModelView): Set[MProperty] do
138 var set
= new HashSet[MProperty]
139 for mclassdef
in mclassdefs
do
140 for mprop
in mclassdef
.intro_mproperties
do
141 if not view
.accept_mentity
(mprop
) then continue
148 # Collect all mproperties redefined in 'self' with `visibility >= min_visibility`.
149 fun collect_redef_mproperties
(view
: ModelView): Set[MProperty] do
150 var set
= new HashSet[MProperty]
151 for mclassdef
in mclassdefs
do
152 for mpropdef
in mclassdef
.mpropdefs
do
153 if mpropdef
.mproperty
.intro_mclassdef
.mclass
== self then continue
154 if not view
.accept_mentity
(mpropdef
) then continue
155 set
.add
(mpropdef
.mproperty
)
161 # Collect mproperties introduced and redefined in 'self' with `visibility >= min_visibility`.
162 fun collect_local_mproperties
(view
: ModelView): Set[MProperty] do
163 var set
= new HashSet[MProperty]
164 set
.add_all collect_intro_mproperties
(view
)
165 set
.add_all collect_redef_mproperties
(view
)
169 # Collect all mproperties inehrited by 'self' with `visibility >= min_visibility`.
170 fun collect_inherited_mproperties
(view
: ModelView): Set[MProperty] do
171 var set
= new HashSet[MProperty]
172 for parent
in collect_parents
(view
) do
173 set
.add_all
(parent
.collect_intro_mproperties
(view
))
174 set
.add_all
(parent
.collect_inherited_mproperties
(view
))
179 # Collect all mproperties accessible by 'self' with `visibility >= min_visibility`.
181 # This include introduced, redefined, inherited mproperties.
182 fun collect_accessible_mproperties
(view
: ModelView): Set[MProperty] do
183 var set
= new HashSet[MProperty]
184 set
.add_all
(collect_intro_mproperties
(view
))
185 set
.add_all
(collect_redef_mproperties
(view
))
186 set
.add_all
(collect_inherited_mproperties
(view
))
190 # Collect mmethods introduced in 'self' with `visibility >= min_visibility`.
191 fun collect_intro_mmethods
(view
: ModelView): Set[MMethod] do
192 var res
= new HashSet[MMethod]
193 for mproperty
in collect_intro_mproperties
(view
) do
194 if mproperty
isa MMethod then res
.add
(mproperty
)
199 # Collect mmethods redefined in 'self' with `visibility >= min_visibility`.
200 fun collect_redef_mmethods
(view
: ModelView): Set[MMethod] do
201 var res
= new HashSet[MMethod]
202 for mproperty
in collect_redef_mproperties
(view
) do
203 if mproperty
isa MMethod then res
.add
(mproperty
)
208 # Collect mmethods introduced and redefined in 'self' with `visibility >= min_visibility`.
209 fun collect_local_mmethods
(view
: ModelView): Set[MMethod] do
210 var set
= new HashSet[MMethod]
211 set
.add_all collect_intro_mmethods
(view
)
212 set
.add_all collect_redef_mmethods
(view
)
216 # Collect mattributes introduced in 'self' with `visibility >= min_visibility`.
217 fun collect_intro_mattributes
(view
: ModelView): Set[MAttribute] do
218 var res
= new HashSet[MAttribute]
219 for mproperty
in collect_intro_mproperties
(view
) do
220 if mproperty
isa MAttribute then res
.add
(mproperty
)
225 # Collect mattributes redefined in 'self' with `visibility >= min_visibility`.
226 fun collect_redef_mattributes
(view
: ModelView): Set[MAttribute] do
227 var res
= new HashSet[MAttribute]
228 for mproperty
in collect_redef_mproperties
(view
) do
229 if mproperty
isa MAttribute then res
.add
(mproperty
)
234 # Collect mattributes introduced and redefined in 'self' with `visibility >= min_visibility`.
235 fun collect_local_mattributes
(view
: ModelView): Set[MAttribute] do
236 var set
= new HashSet[MAttribute]
237 set
.add_all collect_intro_mattributes
(view
)
238 set
.add_all collect_redef_mattributes
(view
)
242 # Collect mattributes inherited by 'self' with `visibility >= min_visibility`.
243 fun collect_inherited_mattributes
(view
: ModelView): Set[MAttribute] do
244 var res
= new HashSet[MAttribute]
245 for mproperty
in collect_inherited_mproperties
(view
) do
246 if mproperty
isa MAttribute then res
.add
(mproperty
)
251 # Collect all mattributes accessible by 'self' with `visibility >= min_visibility`.
253 # This include introduced, redefined, inherited mattributes.
254 fun collect_accessible_mattributes
(view
: ModelView): Set[MAttribute] do
255 var set
= new HashSet[MAttribute]
256 set
.add_all
(collect_intro_mattributes
(view
))
257 set
.add_all
(collect_redef_mattributes
(view
))
258 set
.add_all
(collect_inherited_mattributes
(view
))
263 redef class MClassDef
265 # Collect mpropdefs in 'self' with `visibility >= min_visibility`.
266 fun collect_mpropdefs
(view
: ModelView): Set[MPropDef] do
267 var res
= new HashSet[MPropDef]
268 for mpropdef
in mpropdefs
do
269 if not view
.accept_mentity
(mpropdef
) then continue
275 # Collect mpropdefs introduced in 'self' with `visibility >= min_visibility`.
276 fun collect_intro_mpropdefs
(view
: ModelView): Set[MPropDef] do
277 var res
= new HashSet[MPropDef]
278 for mpropdef
in mpropdefs
do
279 if not mpropdef
.is_intro
then continue
280 if not view
.accept_mentity
(mpropdef
) then continue
286 # Collect mpropdefs redefined in 'self' with `visibility >= min_visibility`.
287 fun collect_redef_mpropdefs
(view
: ModelView): Set[MPropDef] do
288 var res
= new HashSet[MPropDef]
289 for mpropdef
in mpropdefs
do
290 if mpropdef
.is_intro
then continue
291 if not view
.accept_mentity
(mpropdef
) then continue
297 # Collect modifiers like redef, private etc.
298 fun collect_modifiers
: Array[String] do
299 var res
= new Array[String]
303 res
.add mclass
.visibility
.to_s
305 res
.add mclass
.kind
.to_s
311 # Collect modifiers like redef, private, abstract, intern, fun etc.
312 fun collect_modifiers
: Array[String] do
313 var res
= new Array[String]
317 res
.add mproperty
.visibility
.to_s
320 if mprop
isa MVirtualTypeDef then
322 else if mprop
isa MMethodDef then
323 if mprop
.is_abstract
then
325 else if mprop
.is_intern
then
328 if mprop
.mproperty
.is_init
then