nitcatalog: adapt to new loader API
[nit.git] / src / metrics / nullables_metrics.nit
index 2c96462..6e9d7ff 100644 (file)
@@ -44,11 +44,11 @@ private class NullablesMetricsPhase
 
                var model = toolcontext.modelbuilder.model
                var mclasses = new HashSet[MClass]
-               for mproject in model.mprojects do
+               for mpackage in model.mpackages do
 
-                       print toolcontext.format_h2("\n ## project {mproject}")
+                       print toolcontext.format_h2("\n ## package {mpackage}")
 
-                       for mgroup in mproject.mgroups do
+                       for mgroup in mpackage.mgroups do
                                if mgroup.mmodules.is_empty then continue
                                metrics.clear
 
@@ -93,7 +93,7 @@ class CNBNA
 
        redef fun collect(mclasses) do
                for mclass in mclasses do
-                       var all = mclass.all_mattributes(mainmodule, min_visibility)
+                       var all = mclass.collect_accessible_mattributes(min_visibility)
                        for mattr in all do
                                if mattr.is_nullable then values.inc(mclass)
                        end
@@ -101,6 +101,15 @@ class CNBNA
        end
 end
 
+redef class MAttribute
+       # Is this attribute nullable for sure?
+       #
+       # This mean that its introduction is declarred with a nullable static type
+       # since attributes are invariant this will work on most cases
+       # attributes with static type anchored with a virtual type are not "nullable for-sure"
+       # because this type can be redefined in subclasses
+       private fun is_nullable: Bool do return intro.static_mtype isa MNullableType
+end
 
 private class NullableSends
        super Visitor
@@ -131,8 +140,8 @@ private class NullableSends
                        end
                        t = t.anchor_to(self.nclassdef.mclassdef.mmodule, self.nclassdef.mclassdef.bound_mtype)
                        if t isa MNullableType then
-                               var name = n.callsite.mproperty.name
-                               if name == "==" or name == "!=" or name == "is_same_instance" then
+                               var p = n.callsite.mproperty
+                               if p.is_null_safe then
                                        self.nullable_eq_sends += 1
                                else
                                        self.nullable_sends += 1