auto_super_init: use CallSite
[nit.git] / src / model_utils.nit
index ebf154a..bc5ca17 100644 (file)
@@ -17,8 +17,7 @@
 # Model exploration and traversing facilities
 module model_utils
 
-import toolcontext
-import exprbuilder
+import modelbuilder
 
 redef class MModule
        # Get the list of mclasses refined in 'self'.
@@ -43,6 +42,16 @@ end
 
 redef class MClass
 
+       # Get the public owner of 'self'.
+       fun public_owner: MModule do
+               var public_owner = self.intro_mmodule.public_owner
+               if public_owner == null then
+                       return self.intro_mmodule
+               else
+                       return public_owner
+               end
+       end
+
        # Get direct parents of 'self'.
        fun parents: Set[MClass] do
                var ret = new HashSet[MClass]
@@ -116,6 +125,17 @@ redef class MClass
                return res
        end
 
+       # Get the set of properties introduced in 'self'.
+       fun intro_mproperties: Set[MProperty] do
+               var res = new HashSet[MProperty]
+               for mclassdef in mclassdefs do
+                       for mpropdef in mclassdef.mpropdefs do
+                               if mpropdef.is_intro then res.add(mpropdef.mproperty)
+                       end
+               end
+               return res
+       end
+
        # Get the list of locally refined methods in 'self'.
        fun redef_methods: Set[MMethod] do
                var res = new HashSet[MMethod]
@@ -129,6 +149,17 @@ redef class MClass
                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]
@@ -140,6 +171,17 @@ redef class MClass
                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]
@@ -187,3 +229,40 @@ redef class MClass
                return self.kind == abstract_kind
        end
 end
+
+# Sorters
+
+# Sort mmodules by their name
+class MModuleNameSorter
+       super AbstractSorter[MModule]
+       redef fun compare(a, b) do return a.name <=> b.name
+       init do end
+end
+
+# Sort mclasses by their name
+class MClassNameSorter
+       super AbstractSorter[MClass]
+       redef fun compare(a, b) do return a.name <=> b.name
+       init do end
+end
+
+# Sort mclassdefs by their name
+class MClassDefNameSorter
+       super AbstractSorter[MClassDef]
+       redef fun compare(a, b) do return a.mclass.name <=> b.mclass.name
+       init do end
+end
+
+# Sort mproperties by their name
+class MPropertyNameSorter
+       super AbstractSorter[MProperty]
+       redef fun compare(a, b) do return a.name <=> b.name
+       init do end
+end
+
+# Sort mpropdefs by their name
+class MPropDefNameSorter
+       super AbstractSorter[MPropDef]
+       redef fun compare(a, b) do return a.mproperty.name <=> b.mproperty.name
+       init do end
+end