print toolcontext.format_h1("\n# MClasses metrics")
var metrics = new MClassMetricSet
+ var min_vis = private_visibility
metrics.register(new CNOA, new CNOP, new CNOC, new CNOD, new CDIT)
- metrics.register(new CNBIP, new CNBRP, new CNBHP)
+ metrics.register(new CNBIP(min_vis), new CNBRP(min_vis), new CNBHP(min_vis))
#TODO metrics.register(new CNBI) # nb init
#TODO metrics.register(new CNBA) # nb attrs
#TODO metrics.register(new CNBM) # nb methods
redef fun name do return "cnbip"
redef fun desc do return "number of introduced properties"
+ var min_visibility: MVisibility
+ init(min_visibility: MVisibility) do self.min_visibility = min_visibility
+
redef fun collect(mclass, mainmodule) do
- values[mclass] = mclass.intro_mproperties.length
+ values[mclass] = mclass.intro_mproperties(min_visibility).length
end
end
redef fun name do return "cnbrp"
redef fun desc do return "number of redefined properties"
+ var min_visibility: MVisibility
+ init(min_visibility: MVisibility) do self.min_visibility = min_visibility
+
redef fun collect(mclass, mainmodule) do
- values[mclass] = mclass.redef_mproperties.length
+ values[mclass] = mclass.redef_mproperties(min_visibility).length
end
end
redef fun name do return "cnbhp"
redef fun desc do return "number of inherited properties"
+ var min_visibility: MVisibility
+ init(min_visibility: MVisibility) do self.min_visibility = min_visibility
+
redef fun collect(mclass, mainmodule) do
- values[mclass] = mclass.inherited_mproperties2(mainmodule).length
+ values[mclass] = mclass.inherited_mproperties(mainmodule, min_visibility).length
end
end
-redef class MClass
- # FIXME wait for cleaning in model_utils
- redef fun intro_mproperties: Set[MProperty] do
- var set = new HashSet[MProperty]
- for mclassdef in mclassdefs do
- set.add_all(mclassdef.intro_mproperties)
- end
- return set
- end
-
- # FIXME wait for cleaning in model_utils
- redef fun redef_mproperties: Set[MProperty] do
- var set = new HashSet[MProperty]
- for mclassdef in mclassdefs do
- for mpropdef in mclassdef.mpropdefs do
- if mpropdef.mproperty.intro_mclassdef.mclass != self then set.add(mpropdef.mproperty)
- end
- end
- return set
- end
-
- # FIXME wait for cleaning in model_utils
- fun inherited_mproperties2(mainmodule: MModule): Set[MProperty] do
- var set = new HashSet[MProperty]
- for parent in in_hierarchy(mainmodule).direct_greaters do
- set.add_all(parent.intro_mproperties)
- set.add_all(parent.inherited_mproperties2(mainmodule))
- end
- return set
- end
-end
return res
end
- # Get the set of properties introduced in 'self'.
- fun intro_mproperties: Set[MProperty] do
- var res = new HashSet[MProperty]
+ # the set of properties introduced in 'self'.
+ fun intro_mproperties(min_visibility: MVisibility): Set[MProperty] do
+ var set = new HashSet[MProperty]
+ for mclassdef in mclassdefs do
+ for mprop in mclassdef.intro_mproperties do
+ if mprop.visibility < min_visibility then continue
+ set.add(mprop)
+ end
+ end
+ return set
+ end
+
+ # the set of locally refined properties in 'self'.
+ fun redef_mproperties(min_visibility: MVisibility): Set[MProperty] do
+ var set = new HashSet[MProperty]
for mclassdef in mclassdefs do
for mpropdef in mclassdef.mpropdefs do
- if mpropdef.is_intro then res.add(mpropdef.mproperty)
+ if mpropdef.mproperty.visibility < min_visibility then continue
+ if mpropdef.mproperty.intro_mclassdef.mclass != self then set.add(mpropdef.mproperty)
end
end
- return res
+ return set
+ end
+
+ # the set of methods inherited by 'self'.
+ fun inherited_mproperties(mainmodule: MModule, min_visibility: MVisibility): Set[MProperty] do
+ var set = new HashSet[MProperty]
+ for parent in in_hierarchy(mainmodule).direct_greaters do
+ set.add_all(parent.intro_mproperties(min_visibility))
+ set.add_all(parent.inherited_mproperties(mainmodule, min_visibility))
+ end
+ return set
+ end
+
+ # the set of introduced and redefined mproperties
+ fun local_mproperties(min_visibility: MVisibility): Set[MProperty] do
+ var set = new HashSet[MProperty]
+ set.add_all(intro_mproperties(min_visibility))
+ set.add_all(redef_mproperties(min_visibility))
+ return set
end
+ # the set of all accessible mproperties for this class
+ fun all_mproperties(mainmodule: MModule, min_visibility: MVisibility): Set[MProperty] do
+ var set = new HashSet[MProperty]
+ set.add_all(local_mproperties(min_visibility))
+ set.add_all(inherited_mproperties(mainmodule, min_visibility))
+ return set
+ end
+
+
# Get the list of locally refined methods in 'self'.
fun redef_methods: Set[MMethod] do
var res = new HashSet[MMethod]
return res
end
- # Get the set of locally refined properties in 'self'.
- fun redef_mproperties: Set[MProperty] do
- var res = new HashSet[MProperty]
- for mclassdef in mclassdefs do
- for mpropdef in mclassdef.mpropdefs do
- if not mpropdef.is_intro then res.add(mpropdef.mproperty)
- end
- end
- return res
- end
-
- # Get the list of methods inherited by 'self'.
fun inherited_methods: Set[MMethod] do
var res = new HashSet[MMethod]
for s in ancestors do
return res
end
- # Get the set of all properties inherited by self
- fun inherited_mproperties: Set[MProperty] do
- var res = new HashSet[MProperty]
- for s in ancestors do
- for m in s.intro_mproperties do
- if not self.intro_mproperties.has(m) and not self.redef_mproperties.has(m) then res.add(m)
- end
- end
- return res
- end
-
# Get the list of all virtual types available in 'self'.
fun virtual_types: Set[MVirtualTypeProp] do
var res = new HashSet[MVirtualTypeProp]