Rename REAMDE to README.md
[nit.git] / src / model_utils.nit
index 3153274..24105e6 100644 (file)
@@ -34,7 +34,7 @@ redef class MConcern
 end
 
 redef class MProject
-       redef fun concern_rank is cached do
+       redef var concern_rank is lazy do
                var max = 0
                for mgroup in mgroups do
                        var mmax = mgroup.concern_rank
@@ -87,7 +87,7 @@ redef class MGroup
                return res
        end
 
-       redef fun concern_rank is cached do
+       redef var concern_rank is lazy do
                var max = 0
                for mmodule in collect_mmodules do
                        var mmax = mmodule.concern_rank
@@ -163,45 +163,7 @@ redef class MModule
                return mclasses
        end
 
-       fun in_nesting_intro_mclasses(min_visibility: MVisibility): Set[MClass] do
-               var res = new HashSet[MClass]
-               for mmodule in in_nesting.greaters do
-                       for mclass in mmodule.filter_intro_mclasses(min_visibility) do
-                               if mclass.visibility < min_visibility then continue
-                               res.add mclass
-                       end
-               end
-               return res
-       end
-
-       fun in_nesting_redef_mclasses(min_visibility: MVisibility): Set[MClass] do
-               var res = new HashSet[MClass]
-               for mmodule in self.in_nesting.greaters do
-                       for mclass in mmodule.filter_redef_mclasses(min_visibility) do
-                               if mclass.visibility < min_visibility then continue
-                               res.add mclass
-                       end
-               end
-               return res
-       end
-
-       fun in_nesting_intro_mclassdefs(min_visibility: MVisibility): Set[MClassDef] do
-               var res = new HashSet[MClassDef]
-               for mmodule in in_nesting.greaters do
-                       res.add_all mmodule.intro_mclassdefs(min_visibility)
-               end
-               return res
-       end
-
-       fun in_nesting_redef_mclassdefs(min_visibility: MVisibility): Set[MClassDef] do
-               var res = new HashSet[MClassDef]
-               for mmodule in self.in_nesting.greaters do
-                       res.add_all mmodule.redef_mclassdefs(min_visibility)
-               end
-               return res
-       end
-
-       redef fun concern_rank is cached do
+       redef var concern_rank is lazy do
                var max = 0
                for p in in_importation.direct_greaters do
                        var pmax = p.concern_rank
@@ -209,6 +171,23 @@ redef class MModule
                end
                return max + 1
        end
+
+       # Find all mmodules nested in `self` if `self` is the default module of a `MGroup`.
+       fun nested_mmodules: Array[MModule] do
+               var res = new Array[MModule]
+               var mgroup = mgroup
+               if mgroup == null or self != mgroup.default_mmodule then return res
+               for mmodule in mgroup.mmodules do
+                       if mmodule == self then continue
+                       res.add mmodule
+               end
+               for nested in mgroup.in_nesting.direct_smallers do
+                       var default = nested.default_mmodule
+                       if default == null then continue
+                       res.add default
+               end
+               return res
+       end
 end
 
 redef class MClass
@@ -528,7 +507,6 @@ class MEntityNameSorter
        super Comparator
        redef type COMPARED: MEntity
        redef fun compare(a, b) do return a.name <=> b.name
-       init do end
 end
 
 # Sort MConcerns based on the module importation hierarchy ranking
@@ -536,7 +514,9 @@ end
 #
 # Comparison is made with the formula:
 #
-#     a.concern_rank + a.booster_rank <=> b.concern_rank + b.booster_ran
+# ~~~nitish
+# a.concern_rank + a.booster_rank <=> b.concern_rank + b.booster_ran
+# ~~~
 #
 # If both `a` and `b` have the same ranking,
 # ordering is based on lexicographic comparison of `a.name` and `b.name`
@@ -544,8 +524,6 @@ class MConcernRankSorter
        super Comparator
        redef type COMPARED: MConcern
 
-       init do end
-
        redef fun compare(a, b) do
                if a.concern_rank == b.concern_rank then
                        return a.name <=> b.name