doc: misc proofread
[nit.git] / src / metrics / mclassdef_collect.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 # This module redef Mclassdef to add new collect methods.
15
16 module mclassdef_collect
17
18 # We usualy need specific phases
19 # NOTE: `frontend` is sufficent in most cases (it is often too much)
20 import frontend
21 import model_collect
22
23 redef class MClassDef
24 # Collect all mproperties introduced in 'self' with `visibility >= min_visibility`.
25 fun collect_intro_mproperties(filter: ModelFilter): Set[MProperty] do
26 var set = new HashSet[MProperty]
27 for mprop in self.intro_mproperties do
28 if not filter.accept_mentity(mprop) then continue
29 set.add(mprop)
30 end
31 return set
32 end
33
34 # Collect mmethods introduced in 'self' with `visibility >= min_visibility`.
35 fun collect_intro_mmethods(filter: ModelFilter): Set[MMethod] do
36 var res = new HashSet[MMethod]
37 for mproperty in collect_intro_mproperties(filter) do
38 if not filter.accept_mentity(mproperty) then continue
39 if mproperty isa MMethod then res.add(mproperty)
40 end
41 return res
42 end
43
44 # Collect mmethods redefined in 'self' with `visibility >= min_visibility`.
45 fun collect_redef_mmethods(filter: ModelFilter): Set[MMethod] do
46 var res = new HashSet[MMethod]
47 for mproperty in collect_redef_mproperties(filter) do
48 if not filter.accept_mentity(mproperty) then continue
49 if mproperty isa MMethod then res.add(mproperty)
50 end
51 return res
52 end
53
54 # Collect mattributes redefined in 'self' with `visibility >= min_visibility`.
55 fun collect_redef_mattributes(filter: ModelFilter): Set[MAttribute] do
56 var res = new HashSet[MAttribute]
57 for mproperty in collect_redef_mproperties(filter) do
58 if not filter.accept_mentity(mproperty) then continue
59 if mproperty isa MAttribute then res.add(mproperty)
60 end
61 return res
62 end
63
64 # Collect mattributes introduced in 'self' with `visibility >= min_visibility`.
65 fun collect_intro_mattributes(filter: ModelFilter): Set[MAttribute] do
66 var res = new HashSet[MAttribute]
67 for mproperty in collect_intro_mproperties(filter) do
68 if not filter.accept_mentity(mproperty) then continue
69 if mproperty isa MAttribute then res.add(mproperty)
70 end
71 return res
72 end
73
74 # Collect all mproperties redefined in 'self' with `visibility >= min_visibility`.
75 fun collect_redef_mproperties(filter: ModelFilter): Set[MProperty] do
76 var set = new HashSet[MProperty]
77 for mpropdef in self.mpropdefs do
78 if not filter.accept_mentity(mpropdef) then continue
79 if mpropdef.mproperty.intro_mclassdef.mclass == self then continue
80 set.add(mpropdef.mproperty)
81 end
82 return set
83 end
84
85 # Collect mmethods inherited by 'self' if accepted by `filter`.
86 fun collect_inherited_mmethods(mainmodule: MModule, filter: ModelFilter): Set[MMethod] do
87 var res = new HashSet[MMethod]
88 for mproperty in collect_inherited_mproperties(mainmodule, filter) do
89 if not filter.accept_mentity(mproperty) then continue
90 if mproperty isa MMethod then res.add(mproperty)
91 end
92 return res
93 end
94
95 # Collect mproperties introduced and redefined in 'self' with `visibility >= min_visibility`.
96 fun collect_local_mproperties(filter: ModelFilter): Set[MProperty] do
97 var set = new HashSet[MProperty]
98 set.add_all collect_intro_mproperties(filter)
99 set.add_all collect_redef_mproperties(filter)
100 return set
101 end
102
103 # Collect all mproperties inehrited by 'self' with `visibility >= min_visibility`.
104 fun collect_inherited_mproperties(mainmodule: MModule, filter: ModelFilter): Set[MProperty] do
105 var set = new HashSet[MProperty]
106 for parent in collect_parents(mainmodule, filter) do
107 set.add_all(parent.collect_intro_mproperties(filter))
108 set.add_all(parent.collect_inherited_mproperties(mainmodule, filter))
109 end
110 return set
111 end
112
113 # Collect mattributes inherited by 'self' with `visibility >= min_visibility`.
114 fun collect_inherited_mattributes(mainmodule: MModule, filter: ModelFilter): Set[MAttribute] do
115 var res = new HashSet[MAttribute]
116 for mproperty in collect_inherited_mproperties(mainmodule, filter) do
117 if not filter.accept_mentity(mproperty) then continue
118 if mproperty isa MAttribute then res.add(mproperty)
119 end
120 return res
121 end
122
123 # Collect all mmethod inehrited,intro and redef
124 fun collect_all_methods(mainmodule: MModule, filter: ModelFilter): Set[MMethod] do
125 var set = new HashSet[MMethod]
126 set.add_all collect_intro_mmethods(filter)
127 set.add_all collect_redef_mmethods(filter)
128 set.add_all collect_inherited_mmethods(mainmodule, filter)
129 return set
130 end
131
132 # Collect all mattributs inehrited,intro and redef
133 fun collect_all_mattributes(mainmodule: MModule, filter: ModelFilter): Set[MAttribute] do
134 var set = new HashSet[MAttribute]
135 set.add_all collect_redef_mattributes(filter)
136 set.add_all collect_intro_mattributes(filter)
137 set.add_all collect_inherited_mattributes(mainmodule, filter)
138 return set
139 end
140
141 # Collect intro and redef mmethods
142 fun collect_intro_and_redef_methods(filter: ModelFilter): Set[MMethod] do
143 var set = new HashSet[MMethod]
144 set.add_all collect_intro_mmethods(filter)
145 set.add_all collect_redef_mmethods(filter)
146 return set
147 end
148
149 # Collect intro and redef mattributs
150 fun collect_intro_and_redef_mattributes(filter: ModelFilter): Set[MAttribute] do
151 var set = new HashSet[MAttribute]
152 set.add_all collect_redef_mattributes(filter)
153 set.add_all collect_intro_mattributes(filter)
154 return set
155 end
156
157 # Collect intro and redef mpropdefs
158 fun collect_intro_and_redef_mpropdefs(filter: ModelFilter): Set[MPropDef] do
159 var set = new HashSet[MPropDef]
160 set.add_all collect_intro_mpropdefs(filter)
161 set.add_all collect_redef_mpropdefs(filter)
162 return set
163 end
164
165 # Collect intro abstract mmethodDef
166 fun collect_abstract_methods(filter: ModelFilter): Set[MMethodDef] do
167 var set = new HashSet[MMethodDef]
168 var mpropdefs = collect_intro_mpropdefs(filter)
169 for mpropdef in mpropdefs do
170 if mpropdef isa MMethodDef then
171 if mpropdef.is_abstract then set.add(mpropdef)
172 end
173 end
174 return set
175 end
176
177 # Collect not defined properties
178 fun collect_not_define_properties(filter: ModelFilter):Set[MMethodDef] do
179 var set = new HashSet[MMethodDef]
180 for mpropdef in collect_abstract_methods(filter) do
181 var redef_count = 0
182 for mprop in mpropdef.mproperty.mpropdefs do
183 if mprop.is_abstract then continue
184 redef_count += 1
185 end
186 if redef_count == 0 then set.add(mpropdef)
187 end
188 return set
189 end
190 end