model_utils: All modules concerned in a class
authorStefan Lage <lagestfan@gmail.com>
Fri, 28 Jun 2013 18:20:24 +0000 (14:20 -0400)
committerStefan Lage <lagestfan@gmail.com>
Wed, 3 Jul 2013 20:54:23 +0000 (16:54 -0400)
Creating a function to all modules an submodules concerned in a class

Signed-off-by: Stefan Lage <lagestfan@gmail.com>

src/model_utils.nit

index 7963eda..4d8d615 100644 (file)
@@ -186,6 +186,25 @@ redef class MClass
                return mdls
        end
 
+       # Get the list of MModule concern in 'self'
+       fun concerns: HashMap[MModule, nullable List[MModule]] do
+               var hm = new HashMap[MModule, nullable List[MModule]]
+               for mmodule in mmodules do
+                       var owner = mmodule.public_owner
+                       if owner == null then
+                               hm[mmodule] = null
+                       else
+                               if hm.has_key(owner) then
+                                       hm[owner].add(mmodule)
+                               else
+                                       hm[owner] = new List[MModule]
+                                       hm[owner].add(mmodule)
+                               end
+                       end
+               end
+               return hm
+       end
+
        fun is_class: Bool do
                return self.kind == concrete_kind or self.kind == abstract_kind
        end