5b6c937ab9d6fef0d8539e192e409bbd35e68b12
[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 case (it is often too much)
20 import frontend
21 import model_views
22 import model_collect
23
24 redef class MClassDef
25 # Collect all mproperties introduced in 'self' with `visibility >= min_visibility`.
26 fun collect_intro_mproperties(view: ModelView): Set[MProperty] do
27 var set = new HashSet[MProperty]
28 for mprop in self.intro_mproperties do
29 if not view.accept_mentity(mprop) then continue
30 set.add(mprop)
31 end
32 return set
33 end
34
35 # Collect mmethods introduced in 'self' with `visibility >= min_visibility`.
36 fun collect_intro_mmethods(view: ModelView): Set[MMethod] do
37 var res = new HashSet[MMethod]
38 for mproperty in collect_intro_mproperties(view) do
39 if not view.accept_mentity(mproperty) then continue
40 if mproperty isa MMethod then res.add(mproperty)
41 end
42 return res
43 end
44
45 # Collect mmethods redefined in 'self' with `visibility >= min_visibility`.
46 fun collect_redef_mmethods(view: ModelView): Set[MMethod] do
47 var res = new HashSet[MMethod]
48 for mproperty in collect_redef_mproperties(view) do
49 if not view.accept_mentity(mproperty) then continue
50 if mproperty isa MMethod then res.add(mproperty)
51 end
52 return res
53 end
54
55 # Collect mattributes redefined in 'self' with `visibility >= min_visibility`.
56 fun collect_redef_mattributes(view: ModelView): Set[MAttribute] do
57 var res = new HashSet[MAttribute]
58 for mproperty in collect_redef_mproperties(view) do
59 if not view.accept_mentity(mproperty) then continue
60 if mproperty isa MAttribute then res.add(mproperty)
61 end
62 return res
63 end
64
65 # Collect mattributes introduced in 'self' with `visibility >= min_visibility`.
66 fun collect_intro_mattributes(view: ModelView): Set[MAttribute] do
67 var res = new HashSet[MAttribute]
68 for mproperty in collect_intro_mproperties(view) do
69 if not view.accept_mentity(mproperty) then continue
70 if mproperty isa MAttribute then res.add(mproperty)
71 end
72 return res
73 end
74
75 # Collect all mproperties redefined in 'self' with `visibility >= min_visibility`.
76 fun collect_redef_mproperties(view: ModelView): Set[MProperty] do
77 var set = new HashSet[MProperty]
78 for mpropdef in self.mpropdefs do
79 if not view.accept_mentity(mpropdef) then continue
80 if mpropdef.mproperty.intro_mclassdef.mclass == self then continue
81 set.add(mpropdef.mproperty)
82 end
83 return set
84 end
85
86 # Collect mmethods inherited by 'self' if accepted by `view`.
87 fun collect_inherited_mmethods(view: ModelView): Set[MMethod] do
88 var res = new HashSet[MMethod]
89 for mproperty in collect_inherited_mproperties(view) do
90 if not view.accept_mentity(mproperty) then continue
91 if mproperty isa MMethod then res.add(mproperty)
92 end
93 return res
94 end
95
96 # Collect mproperties introduced and redefined in 'self' with `visibility >= min_visibility`.
97 fun collect_local_mproperties(view: ModelView): Set[MProperty] do
98 var set = new HashSet[MProperty]
99 set.add_all collect_intro_mproperties(view)
100 set.add_all collect_redef_mproperties(view)
101 return set
102 end
103
104 # Collect all mproperties inehrited by 'self' with `visibility >= min_visibility`.
105 fun collect_inherited_mproperties(view: ModelView): Set[MProperty] do
106 var set = new HashSet[MProperty]
107 for parent in collect_parents(view) do
108 set.add_all(parent.collect_intro_mproperties(view))
109 set.add_all(parent.collect_inherited_mproperties(view))
110 end
111 return set
112 end
113
114 # Collect mattributes inherited by 'self' with `visibility >= min_visibility`.
115 fun collect_inherited_mattributes(view: ModelView): Set[MAttribute] do
116 var res = new HashSet[MAttribute]
117 for mproperty in collect_inherited_mproperties(view) do
118 if not view.accept_mentity(mproperty) then continue
119 if mproperty isa MAttribute then res.add(mproperty)
120 end
121 return res
122 end
123
124 fun collect_all_methods(view: ModelView): Set[MMethod] do
125 var set = new HashSet[MMethod]
126 set.add_all collect_intro_mmethods(view)
127 set.add_all collect_redef_mmethods(view)
128 set.add_all collect_inherited_mmethods(view)
129 return set
130 end
131
132 fun collect_all_mattributes(view: ModelView): Set[MAttribute] do
133 var set = new HashSet[MAttribute]
134 set.add_all collect_redef_mattributes(view)
135 set.add_all collect_intro_mattributes(view)
136 set.add_all collect_inherited_mattributes(view)
137 return set
138 end
139
140 fun collect_intro_and_redef_methods(view: ModelView): Set[MMethod] do
141 var set = new HashSet[MMethod]
142 set.add_all collect_intro_mmethods(view)
143 set.add_all collect_redef_mmethods(view)
144 return set
145 end
146
147 fun collect_intro_and_redef_mattributes(view: ModelView): Set[MAttribute] do
148 var set = new HashSet[MAttribute]
149 set.add_all collect_redef_mattributes(view)
150 set.add_all collect_intro_mattributes(view)
151 return set
152 end
153
154 fun collect_intro_and_redef_mproperties(view: ModelView): Set[MProperty] do
155 var set = new HashSet[MProperty]
156 set.add_all collect_redef_mproperties(view)
157 set.add_all collect_intro_mproperties(view)
158 return set
159 end
160
161 fun collect_intro_and_redef_mpropdefs(view: ModelView): Set[MPropDef] do
162 var set = new HashSet[MPropDef]
163 set.add_all collect_intro_mpropdefs(view)
164 set.add_all collect_redef_mpropdefs(view)
165 return set
166 end
167 end