model_collect: kill ModelView
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 21 Nov 2017 18:43:38 +0000 (13:43 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 17 May 2018 21:16:29 +0000 (17:16 -0400)
And move services to model_collect

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/model/model_collect.nit
src/model/model_index.nit
src/model/model_views.nit [deleted file]
src/test_model_index.nit
tests/sav/test_model_index_args21.res

index 4df13c6..b27aa9e 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Collect things from a `ModelView`
+# Collect things from the model.
 #
 # This module introduce several usefull methods to list and count things from a
-# ModelView.
+# Model.
 #
-# First setup you view from a Model:
-#
-# ~~~nitih
-# var view = new ModelView(model, mainmodule)
+# ~~~nitish
+# print number of parents for `{my_class}`
+# print my_class.collect_parents.count
 # ~~~
 #
-# Then ask question using the view:
-#
+# Collect methods can also be used with a ModelFilter:
 # ~~~nitish
-# print number of parents for `{my_class}`
-# print my_class.collect_parents(view).count
+# var filter = new ModelFilter(min_visibility = private_visibility)
+# print my_class.collect_parents(filter).count
 # ~~~
 #
 # **Warning**
 #
-# `model_collect` offers a flattened view of the model without considering any
+# `model_collect` offers a flattened filter of the model without considering any
 # main module.
 # For this reason, `model_collect` lists all the definitions reachable from all
 # modules.
 #
-# This is usefull for tools that need a global view of a model like `nitdoc`,
+# This is usefull for tools that need a global filter of a model like `nitdoc`,
 # `nitx`, `nitmetrics` or `nituml`.
 # It should not be used for compiling stuffs like computing VFT, where the listed
 # entities could not be reachable depending on the modules really imported.
 module model_collect
 
-import model_views
+import model_filters
 
 redef class MEntity
 
@@ -63,16 +61,16 @@ redef class MEntity
        # Collect `self` ancestors (direct and indirect)
        #
        # The concept of ancestor is abstract at this stage.
-       fun collect_ancestors(view: ModelView): Set[MENTITY] do
+       fun collect_ancestors(mainmodule: MModule, filter: nullable ModelFilter): Set[MENTITY] do
                var done = new HashSet[MENTITY]
                var todo = new Array[MENTITY]
 
-               todo.add_all collect_parents(view)
+               todo.add_all collect_parents(mainmodule, filter)
                while todo.not_empty do
                        var mentity = todo.pop
                        if mentity == self or done.has(mentity) then continue
                        done.add mentity
-                       todo.add_all mentity.collect_parents(view)
+                       todo.add_all mentity.collect_parents(mainmodule, filter)
                end
                return done
        end
@@ -80,26 +78,26 @@ redef class MEntity
        # Collect `self` parents (direct ancestors)
        #
        # The concept of parent is abstract at this stage.
-       fun collect_parents(view: ModelView): Set[MENTITY] is abstract
+       fun collect_parents(mainmodule: MModule, filter: nullable ModelFilter): Set[MENTITY] is abstract
 
        # Collect `self` children (direct descendants)
        #
        # The concept of child is abstract at this stage.
-       fun collect_children(view: ModelView): Set[MENTITY] is abstract
+       fun collect_children(mainmodule: MModule, filter: nullable ModelFilter): Set[MENTITY] is abstract
 
        # Collect `self` descendants (direct and direct)
        #
        # The concept of descendant is abstract at this stage.
-       fun collect_descendants(view: ModelView): Set[MENTITY] do
+       fun collect_descendants(mainmodule: MModule, filter: nullable ModelFilter): Set[MENTITY] do
                var done = new HashSet[MENTITY]
                var todo = new Array[MENTITY]
 
-               todo.add_all collect_children(view)
+               todo.add_all collect_children(mainmodule, filter)
                while todo.not_empty do
                        var mentity = todo.pop
                        if mentity == self or done.has(mentity) then continue
                        done.add mentity
-                       todo.add_all mentity.collect_children(view)
+                       todo.add_all mentity.collect_children(mainmodule, filter)
                end
                return done
        end
@@ -116,7 +114,7 @@ redef class MEntity
        # * `MClassDef`: classdef inheritance
        # * `MProperty`: property definitions graph (all propdefs flattened)
        # * `MPropDef`: property definitions graph
-       fun hierarchy_poset(view: ModelView): POSet[MENTITY] do
+       fun hierarchy_poset(mainmodule: MModule, filter: nullable ModelFilter): POSet[MENTITY] do
                var poset = new POSet[MENTITY]
                var parents_done = new HashSet[MENTITY]
                var parents = new Array[MENTITY]
@@ -126,7 +124,7 @@ redef class MEntity
                        if parents_done.has(mentity) then continue
                        parents_done.add mentity
                        poset.add_node mentity
-                       for parent in mentity.collect_parents(view) do
+                       for parent in mentity.collect_parents(mainmodule, filter) do
                                poset.add_edge(mentity, parent)
                                parents.add parent
                        end
@@ -138,7 +136,7 @@ redef class MEntity
                        var mentity = children.pop
                        if children_done.has(mentity) then continue
                        children_done.add mentity
-                       for child in mentity.collect_children(view) do
+                       for child in mentity.collect_children(mainmodule, filter) do
                                poset.add_edge(child, mentity)
                                children.add child
                        end
@@ -150,38 +148,116 @@ end
 redef class Model
 
        # Collect all MPackages in `self`
-       fun collect_mpackages(view: ModelView): HashSet[MPackage] do
+       fun collect_mpackages(filter: nullable ModelFilter): HashSet[MPackage] do
                var res = new HashSet[MPackage]
                for mpackage in mpackages do
-                       if not view.accept_mentity(mpackage) then continue
-                       res.add(mpackage)
+                       if filter == null or filter.accept_mentity(mpackage) then res.add(mpackage)
+               end
+               return res
+       end
+
+       # Collect all MGroups in `self`
+       fun collect_mgroups(filter: nullable ModelFilter): HashSet[MGroup] do
+               var res = new HashSet[MGroup]
+               for mpackage in collect_mpackages(filter) do
+                       res.add_all mpackage.collect_all_mgroups(filter)
                end
                return res
        end
 
        # Collect all MModules in `self`
-       fun collect_mmodules(view: ModelView): HashSet[MModule] do
+       fun collect_mmodules(filter: nullable ModelFilter): HashSet[MModule] do
                var res = new HashSet[MModule]
-               for mpackage in collect_mpackages(view) do
-                       res.add_all mpackage.collect_all_mmodules(view)
+               for mpackage in collect_mpackages(filter) do
+                       res.add_all mpackage.collect_all_mmodules(filter)
+               end
+               return res
+       end
+
+       # Collect all MClasses in `self`
+       fun collect_mclasses(filter: nullable ModelFilter): HashSet[MClass] do
+               var res = new HashSet[MClass]
+               for mclass in mclasses do
+                       if filter == null or filter.accept_mentity(mclass) then res.add mclass
                end
                return res
        end
 
        # Collect all MClasses introduced in `self`
-       fun collect_intro_mclasses(view: ModelView): HashSet[MClass] do
+       fun collect_intro_mclasses(filter: nullable ModelFilter): HashSet[MClass] do
                var res = new HashSet[MClass]
-               for mpackage in collect_mpackages(view) do
-                       res.add_all mpackage.collect_intro_mclasses(view)
+               for mpackage in collect_mpackages(filter) do
+                       res.add_all mpackage.collect_intro_mclasses(filter)
+               end
+               return res
+       end
+
+       # Collect all MClassDefs in `self`
+       fun collect_mclassdefs(filter: nullable ModelFilter): HashSet[MClassDef] do
+               var res = new HashSet[MClassDef]
+               for mclass in collect_mclasses(filter) do
+                       res.add_all mclass.collect_mclassdefs(filter)
                end
                return res
        end
 
        # Collect all MProperties introduced in `self`
-       fun collect_intro_mproperties(view: ModelView): HashSet[MProperty] do
+       fun collect_intro_mproperties(filter: nullable ModelFilter): HashSet[MProperty] do
+               var res = new HashSet[MProperty]
+               for mpackage in collect_mpackages(filter) do
+                       res.add_all mpackage.collect_intro_mproperties(filter)
+               end
+               return res
+       end
+
+       # Collect all MProperties in `self`
+       fun collect_mproperties(filter: nullable ModelFilter): HashSet[MProperty] do
                var res = new HashSet[MProperty]
-               for mpackage in collect_mpackages(view) do
-                       res.add_all mpackage.collect_intro_mproperties(view)
+               for mproperty in mproperties do
+                       if filter == null or filter.accept_mentity(mproperty) then res.add mproperty
+               end
+               return res
+       end
+
+       # Collect all MPropDefs in `self`
+       fun collect_mpropdefs(filter: nullable ModelFilter): HashSet[MPropDef] do
+               var res = new HashSet[MPropDef]
+               for mproperty in collect_mproperties(filter) do
+                       for mpropdef in mproperty.mpropdefs do
+                               if filter == null or filter.accept_mentity(mpropdef) then res.add mpropdef
+                       end
+               end
+               return res
+       end
+
+       # Collect all MEntities in `self`
+       fun collect_mentities(filter: nullable ModelFilter): HashSet[MEntity] do
+               var res = new HashSet[MEntity]
+               res.add_all collect_mpackages(filter)
+               res.add_all collect_mgroups(filter)
+               res.add_all collect_mmodules(filter)
+               res.add_all collect_mclasses(filter)
+               res.add_all collect_mclassdefs(filter)
+               res.add_all collect_mproperties(filter)
+               res.add_all collect_mpropdefs(filter)
+               return res
+       end
+
+       # Searches the MEntity that matches `full_name`.
+       fun mentity_by_full_name(full_name: String, filter: nullable ModelFilter): nullable MEntity do
+               for mentity in collect_mentities(filter) do
+                       if filter != null and not filter.accept_mentity(mentity) then continue
+                       if mentity.full_name == full_name then return mentity
+               end
+               return null
+       end
+
+       # Searches the MEntities that matches `full_name`.
+       fun mentities_by_name(name: String, filter: nullable ModelFilter): Array[MEntity] do
+               var res = new Array[MEntity]
+               for mentity in collect_mentities(filter) do
+                       if filter != null and not filter.accept_mentity(mentity) then continue
+                       if mentity.name == name then res.add mentity
                end
                return res
        end
@@ -192,125 +268,124 @@ redef class MPackage
        redef fun collect_modifiers do return super + ["package"]
 
        # Collect all packages directly imported by `self`
-       redef fun collect_parents(view) do
+       redef fun collect_parents(mainmodule, filter) do
                var res = new HashSet[MENTITY]
                for mgroup in mgroups do
-                       for parent in mgroup.collect_parents(view) do
+                       for parent in mgroup.collect_parents(mainmodule, filter) do
                                var mpackage = parent.mpackage
-                               if mpackage == self or not view.accept_mentity(mpackage) then continue
-                               res.add(mpackage)
+                               if mpackage == self then continue
+                               if filter == null or filter.accept_mentity(mpackage) then res.add(mpackage)
                        end
                end
                return res
        end
 
        # Collect all packages that directly depends on `self`
-       redef fun collect_children(view) do
+       redef fun collect_children(mainmodule, filter) do
                var res = new HashSet[MENTITY]
-               for mpackage in view.mpackages do
-                       if mpackage.collect_parents(view).has(self) then res.add mpackage
+               for mpackage in model.collect_mpackages(filter) do
+                       if mpackage.collect_parents(mainmodule, filter).has(self) then res.add mpackage
                end
                return res
        end
 
        # Collect all groups contained in `self`
-       fun collect_all_mgroups(view: ModelView): HashSet[MGroup] do
+       fun collect_all_mgroups(filter: nullable ModelFilter): HashSet[MGroup] do
                var res = new HashSet[MGroup]
                for mgroup in mgroups do
-                       if not view.accept_mentity(mgroup) then continue
-                       res.add(mgroup)
+                       if filter == null or filter.accept_mentity(mgroup) then res.add(mgroup)
                end
                return res
        end
 
        # Collect only groups contained in `self.root`
-       fun collect_mgroups(view: ModelView): HashSet[MGroup] do
+       fun collect_mgroups(filter: nullable ModelFilter): HashSet[MGroup] do
                var res = new HashSet[MGroup]
                var root = self.root
                if root == null then return res
-               res.add_all root.collect_mgroups(view)
+               res.add_all root.collect_mgroups(filter)
                return res
        end
 
        # Collect all modules contained in `self`
-       fun collect_all_mmodules(view: ModelView): HashSet[MModule] do
+       fun collect_all_mmodules(filter: nullable ModelFilter): HashSet[MModule] do
                var res = new HashSet[MModule]
-               for mgroup in collect_all_mgroups(view) do
-                       res.add_all mgroup.collect_mmodules(view)
+               for mgroup in collect_all_mgroups(filter) do
+                       res.add_all mgroup.collect_mmodules(filter)
                end
                return res
        end
 
        # Collect only modules contained in `self.root`
-       fun collect_mmodules(view: ModelView): HashSet[MModule] do
+       fun collect_mmodules(filter: nullable ModelFilter): HashSet[MModule] do
                var res = new HashSet[MModule]
                var root = self.root
                if root == null then return res
-               res.add_all root.collect_mmodules(view)
+               res.add_all root.collect_mmodules(filter)
                return res
        end
 
        # Collect all classes introduced in `self`
-       fun collect_intro_mclasses(view: ModelView): HashSet[MClass] do
+       fun collect_intro_mclasses(filter: nullable ModelFilter): HashSet[MClass] do
                var res = new HashSet[MClass]
                for mgroup in mgroups do
-                       for mmodule in collect_all_mmodules(view) do
-                               res.add_all mmodule.collect_intro_mclasses(view)
+                       for mmodule in collect_all_mmodules(filter) do
+                               res.add_all mmodule.collect_intro_mclasses(filter)
                        end
                end
                return res
        end
 
        # Collect all classes redefined or refined in `self`
-       fun collect_redef_mclasses(view: ModelView): Set[MClass] do
+       fun collect_redef_mclasses(filter: nullable ModelFilter): Set[MClass] do
                var res = new HashSet[MClass]
                for mgroup in mgroups do
-                       for mmodule in collect_all_mmodules(view) do
-                               res.add_all mmodule.collect_redef_mclasses(view)
+                       for mmodule in collect_all_mmodules(filter) do
+                               res.add_all mmodule.collect_redef_mclasses(filter)
                        end
                end
                return res
        end
 
        # Collect all properties introduced in `self`
-       fun collect_intro_mproperties(view: ModelView): HashSet[MProperty] do
+       fun collect_intro_mproperties(filter: nullable ModelFilter): HashSet[MProperty] do
                var res = new HashSet[MProperty]
                for mgroup in mgroups do
-                       for mmodule in collect_all_mmodules(view) do
-                               res.add_all mmodule.collect_intro_mproperties(view)
+                       for mmodule in collect_all_mmodules(filter) do
+                               res.add_all mmodule.collect_intro_mproperties(filter)
                        end
                end
                return res
        end
 
        # Collect all properties redefined in `self`
-       fun collect_redef_mproperties(view: ModelView): HashSet[MProperty] do
+       fun collect_redef_mproperties(filter: nullable ModelFilter): HashSet[MProperty] do
                var res = new HashSet[MProperty]
                for mgroup in mgroups do
-                       for mmodule in collect_all_mmodules(view) do
-                               res.add_all mmodule.collect_redef_mproperties(view)
+                       for mmodule in collect_all_mmodules(filter) do
+                               res.add_all mmodule.collect_redef_mproperties(filter)
                        end
                end
                return res
        end
 
        # Collect all attributes introduced in `self`
-       fun collect_intro_attributes(view: ModelView): Set[MAttribute] do
+       fun collect_intro_attributes(filter: nullable ModelFilter): Set[MAttribute] do
                var res = new HashSet[MAttribute]
                for mgroup in mgroups do
-                       for mmodule in collect_all_mmodules(view) do
-                               res.add_all mmodule.collect_intro_attributes(view)
+                       for mmodule in collect_all_mmodules(filter) do
+                               res.add_all mmodule.collect_intro_attributes(filter)
                        end
                end
                return res
        end
 
        # Collect all inits introduced in `self`
-       fun collect_intro_inits(view: ModelView): Set[MMethod] do
+       fun collect_intro_inits(filter: nullable ModelFilter): Set[MMethod] do
                var res = new HashSet[MMethod]
                for mgroup in mgroups do
-                       for mmodule in collect_all_mmodules(view) do
-                               res.add_all mmodule.collect_intro_inits(view)
+                       for mmodule in collect_all_mmodules(filter) do
+                               res.add_all mmodule.collect_intro_inits(filter)
                        end
                end
                return res
@@ -319,22 +394,22 @@ redef class MPackage
        # Collect all methods introduced in `self` excluding inits
        #
        # See `collect_intro_inits`.
-       fun collect_intro_methods(view: ModelView): Set[MMethod] do
+       fun collect_intro_methods(filter: nullable ModelFilter): Set[MMethod] do
                var res = new HashSet[MMethod]
                for mgroup in mgroups do
-                       for mmodule in collect_all_mmodules(view) do
-                               res.add_all mmodule.collect_intro_methods(view)
+                       for mmodule in collect_all_mmodules(filter) do
+                               res.add_all mmodule.collect_intro_methods(filter)
                        end
                end
                return res
        end
 
        # Collect all virtual types introduced in `self`
-       fun collect_intro_vts(view: ModelView): Set[MVirtualTypeProp] do
+       fun collect_intro_vts(filter: nullable ModelFilter): Set[MVirtualTypeProp] do
                var res = new HashSet[MVirtualTypeProp]
                for mgroup in mgroups do
-                       for mmodule in collect_all_mmodules(view) do
-                               res.add_all mmodule.collect_intro_vts(view)
+                       for mmodule in collect_all_mmodules(filter) do
+                               res.add_all mmodule.collect_intro_vts(filter)
                        end
                end
                return res
@@ -346,54 +421,52 @@ redef class MGroup
        redef fun collect_modifiers do return super + ["group"]
 
        # Collect all groups directly import by `self`
-       redef fun collect_parents(view) do
+       redef fun collect_parents(mainmodule, filter) do
                var res = new HashSet[MENTITY]
                for mmodule in mmodules do
-                       for parent in mmodule.collect_parents(view) do
+                       for parent in mmodule.collect_parents(mainmodule, filter) do
                                var mgroup = parent.mgroup
                                if mgroup == null or mgroup == self then continue
-                               if not view.accept_mentity(mgroup) then continue
-                               res.add(mgroup)
+                               if filter == null or filter.accept_mentity(mgroup) then res.add(mgroup)
                        end
                end
                return res
        end
 
        # Collect all group that directly import `self`
-       redef fun collect_children(view) do
+       redef fun collect_children(mainmodule, filter) do
                var res = new HashSet[MENTITY]
-               for mgroup in view.mgroups do
-                       if mgroup == self or not view.accept_mentity(mgroup) then continue
-                       if mgroup.collect_parents(view).has(self) then res.add mgroup
+               for mgroup in model.collect_mgroups(filter) do
+                       if mgroup == self then continue
+                       if filter != null and not filter.accept_mentity(mgroup) then continue
+                       if mgroup.collect_parents(mainmodule, filter).has(self) then res.add mgroup
                end
                return res
        end
 
        # Collect all groups contained in `self`
-       fun collect_mgroups(view: ModelView): HashSet[MENTITY] do
+       fun collect_mgroups(filter: nullable ModelFilter): HashSet[MENTITY] do
                var res = new HashSet[MENTITY]
                for mgroup in in_nesting.direct_smallers do
-                       if not view.accept_mentity(mgroup) then continue
-                       res.add(mgroup)
+                       if filter == null or filter.accept_mentity(mgroup) then res.add(mgroup)
                end
                return res
        end
 
        # Collect all modules contained in `self`
-       fun collect_all_mmodules(view: ModelView): HashSet[MModule] do
+       fun collect_all_mmodules(filter: nullable ModelFilter): HashSet[MModule] do
                var res = new HashSet[MModule]
-               for mgroup in collect_mgroups(view) do
-                       res.add_all mgroup.collect_all_mmodules(view)
+               for mgroup in collect_mgroups(filter) do
+                       res.add_all mgroup.collect_all_mmodules(filter)
                end
                return res
        end
 
        # Collect all modules contained in `self`
-       fun collect_mmodules(view: ModelView): HashSet[MModule] do
+       fun collect_mmodules(filter: nullable ModelFilter): HashSet[MModule] do
                var res = new HashSet[MModule]
                for mmodule in mmodules do
-                       if not view.accept_mentity(mmodule) then continue
-                       res.add(mmodule)
+                       if filter == null or filter.accept_mentity(mmodule) then res.add(mmodule)
                end
                return res
        end
@@ -404,121 +477,125 @@ redef class MModule
        redef fun collect_modifiers do return super + ["module"]
 
        # Collect all modules directly imported by `self`
-       redef fun collect_parents(view) do
+       redef fun collect_ancestors(mainmodule, filter) do
+               var res = new HashSet[MENTITY]
+               for mentity in in_importation.greaters do
+                       if mentity == self then continue
+                       if filter == null or filter.accept_mentity(mentity) then res.add mentity
+               end
+               return res
+       end
+
+       # Collect all modules directly imported by `self`
+       redef fun collect_parents(mainmodule, filter) do
                var res = new HashSet[MENTITY]
                for mentity in in_importation.direct_greaters do
                        if mentity == self then continue
-                       if not view.accept_mentity(mentity) then continue
-                       res.add mentity
+                       if filter == null or filter.accept_mentity(mentity) then res.add mentity
                end
                return res
        end
 
        # Collect all modules that directly import `self`
-       redef fun collect_children(view) do
+       redef fun collect_children(mainmodule, filter) do
                var res = new HashSet[MENTITY]
                for mentity in in_importation.direct_smallers do
                        if mentity == self then continue
-                       if not view.accept_mentity(mentity) then continue
-                       res.add mentity
+                       if filter == null or filter.accept_mentity(mentity) then res.add mentity
                end
                return res
        end
 
        # Collect all module descendants of `self` (direct and transitive imports)
-       redef fun collect_descendants(view) do
+       redef fun collect_descendants(mainmodule, filter) do
                var res = new HashSet[MENTITY]
                for mentity in in_importation.smallers do
                        if mentity == self then continue
-                       if not view.accept_mentity(mentity) then continue
-                       res.add mentity
+                       if filter == null or filter.accept_mentity(mentity) then res.add mentity
                end
                return res
        end
 
        # Collect all class definitions introduced in `self`
-       fun collect_intro_mclassdefs(view: ModelView): Set[MClassDef] do
+       fun collect_intro_mclassdefs(filter: nullable ModelFilter): Set[MClassDef] do
                var res = new HashSet[MClassDef]
                for mclassdef in mclassdefs do
                        if not mclassdef.is_intro then continue
-                       if not view.accept_mentity(mclassdef) then continue
-                       res.add mclassdef
+                       if filter == null or filter.accept_mentity(mclassdef) then res.add mclassdef
                end
                return res
        end
 
        # Collect all class definitions refined in `self`
-       fun collect_redef_mclassdefs(view: ModelView): Set[MClassDef] do
+       fun collect_redef_mclassdefs(filter: nullable ModelFilter): Set[MClassDef] do
                var res = new HashSet[MClassDef]
                for mclassdef in mclassdefs do
                        if mclassdef.is_intro then continue
-                       if not view.accept_mentity(mclassdef) then continue
-                       res.add mclassdef
+                       if filter == null or filter.accept_mentity(mclassdef) then res.add mclassdef
                end
                return res
        end
 
        # Collect all class definitions introduced and refined in `self`
-       fun collect_local_mclassdefs(view: ModelView): Set[MClassDef] do
+       fun collect_local_mclassdefs(filter: nullable ModelFilter): Set[MClassDef] do
                var res = new HashSet[MClassDef]
-               res.add_all collect_intro_mclassdefs(view)
-               res.add_all collect_redef_mclassdefs(view)
+               res.add_all collect_intro_mclassdefs(filter)
+               res.add_all collect_redef_mclassdefs(filter)
                return res
        end
 
        # Collect all classes introduced in `self`
-       fun collect_intro_mclasses(view: ModelView): Set[MClass] do
+       fun collect_intro_mclasses(filter: nullable ModelFilter): Set[MClass] do
                var res = new HashSet[MClass]
                for mclass in intro_mclasses do
-                       if not view.accept_mentity(mclass) then continue
-                       res.add mclass
+                       if filter == null or filter.accept_mentity(mclass) then res.add mclass
                end
                return res
        end
 
        # Collect all classes refined in `self`
-       fun collect_redef_mclasses(view: ModelView): Set[MClass] do
+       fun collect_redef_mclasses(filter: nullable ModelFilter): Set[MClass] do
                var mclasses = new HashSet[MClass]
                for mclassdef in mclassdefs do
-                       if not view.accept_mentity(mclassdef.mclass) then continue
+                       if filter != null and not filter.accept_mentity(mclassdef.mclass) then continue
                        if not mclassdef.is_intro then mclasses.add(mclassdef.mclass)
                end
                return mclasses
        end
 
        # Collect all classes introduced and refined in `self`
-       fun collect_local_mclasses(view: ModelView): Set[MClass] do
+       fun collect_local_mclasses(filter: nullable ModelFilter): Set[MClass] do
                var res = new HashSet[MClass]
-               res.add_all collect_intro_mclasses(view)
-               res.add_all collect_redef_mclasses(view)
+               res.add_all collect_intro_mclasses(filter)
+               res.add_all collect_redef_mclasses(filter)
                return res
        end
 
        # Collect all classes imported from `self` parents
-       fun collect_imported_mclasses(view: ModelView): Set[MClass] do
+       fun collect_imported_mclasses(mainmodule: MModule, filter: nullable ModelFilter): Set[MClass] do
                var res = new HashSet[MClass]
-               for parent in collect_parents(view) do
-                       res.add_all parent.collect_intro_mclasses(view)
-                       res.add_all parent.collect_redef_mclasses(view)
-                       res.add_all parent.collect_imported_mclasses(view)
+               for parent in collect_parents(mainmodule, filter) do
+                       res.add_all parent.collect_intro_mclasses(filter)
+                       res.add_all parent.collect_redef_mclasses(filter)
+                       res.add_all parent.collect_imported_mclasses(mainmodule, filter)
                end
                return res
        end
 
        # Collect all properties introduced in `self`
-       fun collect_intro_mproperties(view: ModelView): Set[MProperty] do
+       fun collect_intro_mproperties(filter: nullable ModelFilter): Set[MProperty] do
                var res = new HashSet[MProperty]
-               for mclass in collect_intro_mclasses(view) do
-                       res.add_all mclass.collect_intro_mproperties(view)
+               for mclass in collect_intro_mclasses(filter) do
+                       res.add_all mclass.collect_intro_mproperties(filter)
                end
                return res
        end
 
        # Collect properties redefined in `self`
-       fun collect_redef_mproperties(view: ModelView): Set[MProperty] do
+       fun collect_redef_mproperties(filter: nullable ModelFilter): Set[MProperty] do
                var res = new HashSet[MProperty]
                for mclassdef in mclassdefs do
-                       for mpropdef in mclassdef.collect_redef_mpropdefs(view) do
+                       for mpropdef in mclassdef.collect_redef_mpropdefs(filter) do
                                res.add mpropdef.mproperty
                        end
                end
@@ -526,36 +603,36 @@ redef class MModule
        end
 
        # Collect attributes introduced in `self`
-       fun collect_intro_attributes(view: ModelView): Set[MAttribute] do
+       fun collect_intro_attributes(filter: nullable ModelFilter): Set[MAttribute] do
                var res = new HashSet[MAttribute]
-               for mproperty in collect_intro_mproperties(view) do
+               for mproperty in collect_intro_mproperties(filter) do
                        if mproperty isa MAttribute then res.add(mproperty)
                end
                return res
        end
 
        # Collect all inits introduced in `self`
-       fun collect_intro_inits(view: ModelView): Set[MMethod] do
+       fun collect_intro_inits(filter: nullable ModelFilter): Set[MMethod] do
                var res = new HashSet[MMethod]
-               for mproperty in collect_intro_mproperties(view) do
+               for mproperty in collect_intro_mproperties(filter) do
                        if mproperty isa MMethod and mproperty.is_init then res.add(mproperty)
                end
                return res
        end
 
        # Collect methods introduced in `self` (without inits)
-       fun collect_intro_methods(view: ModelView): Set[MMethod] do
+       fun collect_intro_methods(filter: nullable ModelFilter): Set[MMethod] do
                var res = new HashSet[MMethod]
-               for mproperty in collect_intro_mproperties(view) do
+               for mproperty in collect_intro_mproperties(filter) do
                        if mproperty isa MMethod and not mproperty.is_init then res.add(mproperty)
                end
                return res
        end
 
        # Collect virtual types introduced in `self`
-       fun collect_intro_vts(view: ModelView): Set[MVirtualTypeProp] do
+       fun collect_intro_vts(filter: nullable ModelFilter): Set[MVirtualTypeProp] do
                var res = new HashSet[MVirtualTypeProp]
-               for mproperty in collect_intro_mproperties(view) do
+               for mproperty in collect_intro_mproperties(filter) do
                        if mproperty isa MVirtualTypeProp then res.add(mproperty)
                end
                return res
@@ -575,11 +652,13 @@ redef class MClass
        # Collect all direct parents of `self`
        #
        # This method uses a flattened hierarchy containing all the mclassdefs.
-       redef fun collect_parents(view) do
+       redef fun collect_parents(mainmodule, filter) do
                var res = new HashSet[MENTITY]
-               if not view.mainmodule.flatten_mclass_hierarchy.has(self) then return res
-               for mclass in in_hierarchy(view.mainmodule).direct_greaters do
-                       if mclass == self or not view.accept_mentity(mclass) then continue
+               if not mainmodule.flatten_mclass_hierarchy.has(self) then return res
+               for mclass in in_hierarchy(mainmodule).direct_greaters do
+                       if mclass == self or (filter != null and not filter.accept_mentity(mclass)) then
+                               continue
+                       end
                        res.add mclass
                end
                return res
@@ -588,91 +667,90 @@ redef class MClass
        # Collect all direct children of `self`
        #
        # This method uses a flattened hierarchy containing all the mclassdefs.
-       redef fun collect_children(view) do
+       redef fun collect_children(mainmodule, filter) do
                var res = new HashSet[MENTITY]
-               if not view.mainmodule.flatten_mclass_hierarchy.has(self) then return res
-               for mclass in in_hierarchy(view.mainmodule).direct_smallers do
-                       if mclass == self or not view.accept_mentity(mclass) then continue
+               if not mainmodule.flatten_mclass_hierarchy.has(self) then return res
+               for mclass in in_hierarchy(mainmodule).direct_smallers do
+                       if mclass == self or (filter != null and not filter.accept_mentity(mclass)) then
+                               continue
+                       end
                        res.add mclass
                end
                return res
        end
 
        # Collect all class definitions of `self`
-       fun collect_mclassdefs(view: ModelView): Set[MClassDef] do
+       fun collect_mclassdefs(filter: nullable ModelFilter): Set[MClassDef] do
                var res = new HashSet[MClassDef]
                for mclassdef in mclassdefs do
-                       if not view.accept_mentity(mclassdef) then continue
-                       res.add mclassdef
+                       if filter == null or filter.accept_mentity(mclassdef) then res.add mclassdef
                end
                return res
        end
 
        # Collect all property definitions that are introductions in `self`
-       fun collect_intro_mpropdefs(view: ModelView): Set[MPropDef] do
+       fun collect_intro_mpropdefs(filter: nullable ModelFilter): Set[MPropDef] do
                var set = new HashSet[MPropDef]
                for mclassdef in mclassdefs do
                        for mpropdef in mclassdef.mpropdefs do
                                if not mpropdef.is_intro then continue
-                               if not view.accept_mentity(mpropdef) then continue
-                               set.add(mpropdef)
+                               if filter == null or filter.accept_mentity(mpropdef) then set.add(mpropdef)
                        end
                end
                return set
        end
 
        # Collect all properties introduced in `self`
-       fun collect_intro_mproperties(view: ModelView): Set[MProperty] do
+       fun collect_intro_mproperties(filter: nullable ModelFilter): Set[MProperty] do
                var set = new HashSet[MProperty]
                for mclassdef in mclassdefs do
                        for mprop in mclassdef.intro_mproperties do
-                               if not view.accept_mentity(mprop) then continue
-                               set.add(mprop)
+                               if filter == null or filter.accept_mentity(mprop) then set.add(mprop)
                        end
                end
                return set
        end
 
        # Collect all propierty definitions that are redefinition in `self`
-       fun collect_redef_mpropdefs(view: ModelView): Set[MPropDef] do
+       fun collect_redef_mpropdefs(filter: nullable ModelFilter): Set[MPropDef] do
                var set = new HashSet[MPropDef]
                for mclassdef in mclassdefs do
                        for mpropdef in mclassdef.mpropdefs do
                                if mpropdef.is_intro then continue
-                               if not view.accept_mentity(mpropdef) then continue
-                               set.add(mpropdef)
+                               if filter == null or filter.accept_mentity(mpropdef) then set.add(mpropdef)
                        end
                end
                return set
        end
 
        # Collect all properties redefined in `self`
-       fun collect_redef_mproperties(view: ModelView): Set[MProperty] do
+       fun collect_redef_mproperties(filter: nullable ModelFilter): 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 continue
-                               if not view.accept_mentity(mpropdef) then continue
-                               set.add(mpropdef.mproperty)
+                               if filter == null or filter.accept_mentity(mpropdef) then
+                                       set.add(mpropdef.mproperty)
+                               end
                        end
                end
                return set
        end
 
        # Collect all properties introduced and redefined in `self`
-       fun collect_local_mproperties(view: ModelView): Set[MProperty] do
+       fun collect_local_mproperties(filter: nullable ModelFilter): Set[MProperty] do
                var set = new HashSet[MProperty]
-               set.add_all collect_intro_mproperties(view)
-               set.add_all collect_redef_mproperties(view)
+               set.add_all collect_intro_mproperties(filter)
+               set.add_all collect_redef_mproperties(filter)
                return set
        end
 
        # Collect all properties inehrited by `self`
-       fun collect_inherited_mproperties(view: ModelView): Set[MProperty] do
+       fun collect_inherited_mproperties(mainmodule: MModule, filter: nullable ModelFilter): Set[MProperty] do
                var set = new HashSet[MProperty]
-               for parent in collect_parents(view) do
-                       set.add_all(parent.collect_intro_mproperties(view))
-                       set.add_all(parent.collect_inherited_mproperties(view))
+               for parent in collect_parents(mainmodule, filter) do
+                       set.add_all(parent.collect_intro_mproperties(filter))
+                       set.add_all(parent.collect_inherited_mproperties(mainmodule, filter))
                end
                return set
        end
@@ -680,44 +758,44 @@ redef class MClass
        # Collect all properties accessible by `self`
        #
        # This include introduced, redefined, inherited properties.
-       fun collect_accessible_mproperties(view: ModelView): Set[MProperty] do
+       fun collect_accessible_mproperties(mainmodule: MModule, filter: nullable ModelFilter): Set[MProperty] do
                var set = new HashSet[MProperty]
-               set.add_all(collect_intro_mproperties(view))
-               set.add_all(collect_redef_mproperties(view))
-               set.add_all(collect_inherited_mproperties(view))
+               set.add_all(collect_intro_mproperties(filter))
+               set.add_all(collect_redef_mproperties(filter))
+               set.add_all(collect_inherited_mproperties(mainmodule, filter))
                return set
        end
 
        # Collect all methods introduced in `self`
-       fun collect_intro_mmethods(view: ModelView): Set[MMethod] do
+       fun collect_intro_mmethods(filter: nullable ModelFilter): Set[MMethod] do
                var res = new HashSet[MMethod]
-               for mproperty in collect_intro_mproperties(view) do
+               for mproperty in collect_intro_mproperties(filter) do
                        if mproperty isa MMethod then res.add(mproperty)
                end
                return res
        end
 
        # Collect all methods redefined in `self`
-       fun collect_redef_mmethods(view: ModelView): Set[MMethod] do
+       fun collect_redef_mmethods(filter: nullable ModelFilter): Set[MMethod] do
                var res = new HashSet[MMethod]
-               for mproperty in collect_redef_mproperties(view) do
+               for mproperty in collect_redef_mproperties(filter) do
                        if mproperty isa MMethod then res.add(mproperty)
                end
                return res
        end
 
        # Collect all methods introduced and redefined in `self`
-       fun collect_local_mmethods(view: ModelView): Set[MMethod] do
+       fun collect_local_mmethods(filter: nullable ModelFilter): Set[MMethod] do
                var set = new HashSet[MMethod]
-               set.add_all collect_intro_mmethods(view)
-               set.add_all collect_redef_mmethods(view)
+               set.add_all collect_intro_mmethods(filter)
+               set.add_all collect_redef_mmethods(filter)
                return set
        end
 
        # Collect all methods inherited by `self`
-       fun collect_inherited_mmethods(view: ModelView): Set[MMethod] do
+       fun collect_inherited_mmethods(mainmodule: MModule, filter: nullable ModelFilter): Set[MMethod] do
                var res = new HashSet[MMethod]
-               for mproperty in collect_inherited_mproperties(view) do
+               for mproperty in collect_inherited_mproperties(mainmodule, filter) do
                        if mproperty isa MMethod then res.add(mproperty)
                end
                return res
@@ -726,44 +804,44 @@ redef class MClass
        # Collect all methods accessible by `self`
        #
        # This include introduced, redefined, inherited methods.
-       fun collect_accessible_mmethods(view: ModelView): Set[MMethod] do
+       fun collect_accessible_mmethods(mainmodule: MModule, filter: nullable ModelFilter): Set[MMethod] do
                var set = new HashSet[MMethod]
-               set.add_all(collect_intro_mmethods(view))
-               set.add_all(collect_redef_mmethods(view))
-               set.add_all(collect_inherited_mmethods(view))
+               set.add_all(collect_intro_mmethods(filter))
+               set.add_all(collect_redef_mmethods(filter))
+               set.add_all(collect_inherited_mmethods(mainmodule, filter))
                return set
        end
 
        # Collect all attributes introduced in `self`
-       fun collect_intro_mattributes(view: ModelView): Set[MAttribute] do
+       fun collect_intro_mattributes(filter: nullable ModelFilter): Set[MAttribute] do
                var res = new HashSet[MAttribute]
-               for mproperty in collect_intro_mproperties(view) do
+               for mproperty in collect_intro_mproperties(filter) do
                        if mproperty isa MAttribute then res.add(mproperty)
                end
                return res
        end
 
        # Collect all attributes redefined in `self`
-       fun collect_redef_mattributes(view: ModelView): Set[MAttribute] do
+       fun collect_redef_mattributes(filter: nullable ModelFilter): Set[MAttribute] do
                var res = new HashSet[MAttribute]
-               for mproperty in collect_redef_mproperties(view) do
+               for mproperty in collect_redef_mproperties(filter) do
                        if mproperty isa MAttribute then res.add(mproperty)
                end
                return res
        end
 
        # Collect all attributes introduced and redefined in `self`
-       fun collect_local_mattributes(view: ModelView): Set[MAttribute] do
+       fun collect_local_mattributes(filter: nullable ModelFilter): Set[MAttribute] do
                var set = new HashSet[MAttribute]
-               set.add_all collect_intro_mattributes(view)
-               set.add_all collect_redef_mattributes(view)
+               set.add_all collect_intro_mattributes(filter)
+               set.add_all collect_redef_mattributes(filter)
                return set
        end
 
        # Collect all attributes inherited by `self`
-       fun collect_inherited_mattributes(view: ModelView): Set[MAttribute] do
+       fun collect_inherited_mattributes(mainmodule: MModule, filter: nullable ModelFilter): Set[MAttribute] do
                var res = new HashSet[MAttribute]
-               for mproperty in collect_inherited_mproperties(view) do
+               for mproperty in collect_inherited_mproperties(mainmodule, filter) do
                        if mproperty isa MAttribute then res.add(mproperty)
                end
                return res
@@ -772,44 +850,44 @@ redef class MClass
        # Collect all attributes accessible by `self`
        #
        # This include introduced, redefined, inherited mattributes.
-       fun collect_accessible_mattributes(view: ModelView): Set[MAttribute] do
+       fun collect_accessible_mattributes(mainmodule: MModule, filter: nullable ModelFilter): Set[MAttribute] do
                var set = new HashSet[MAttribute]
-               set.add_all(collect_intro_mattributes(view))
-               set.add_all(collect_redef_mattributes(view))
-               set.add_all(collect_inherited_mattributes(view))
+               set.add_all(collect_intro_mattributes(filter))
+               set.add_all(collect_redef_mattributes(filter))
+               set.add_all(collect_inherited_mattributes(mainmodule, filter))
                return set
        end
 
        # Collect all init methods introduced in `self`
-       fun collect_intro_inits(view: ModelView): Set[MMethod] do
+       fun collect_intro_inits(filter: nullable ModelFilter): Set[MMethod] do
                var res = new HashSet[MMethod]
-               for mproperty in collect_intro_mmethods(view) do
+               for mproperty in collect_intro_mmethods(filter) do
                        if mproperty.is_init then res.add(mproperty)
                end
                return res
        end
 
        # Collect all init methods redefined in `self`
-       fun collect_redef_inits(view: ModelView): Set[MMethod] do
+       fun collect_redef_inits(filter: nullable ModelFilter): Set[MMethod] do
                var res = new HashSet[MMethod]
-               for mproperty in collect_redef_mmethods(view) do
+               for mproperty in collect_redef_mmethods(filter) do
                        if mproperty.is_init then res.add(mproperty)
                end
                return res
        end
 
        # Collect all init methods introduced and redefined in `self`
-       fun collect_local_inits(view: ModelView): Set[MMethod] do
+       fun collect_local_inits(filter: nullable ModelFilter): Set[MMethod] do
                var set = new HashSet[MMethod]
-               set.add_all collect_intro_inits(view)
-               set.add_all collect_redef_inits(view)
+               set.add_all collect_intro_inits(filter)
+               set.add_all collect_redef_inits(filter)
                return set
        end
 
        # Collect all init methods inherited by `self`
-       fun collect_inherited_inits(view: ModelView): Set[MMethod] do
+       fun collect_inherited_inits(mainmodule: MModule, filter: nullable ModelFilter): Set[MMethod] do
                var res = new HashSet[MMethod]
-               for mproperty in collect_inherited_mmethods(view) do
+               for mproperty in collect_inherited_mmethods(mainmodule, filter) do
                        if mproperty.is_init then res.add(mproperty)
                end
                return res
@@ -818,44 +896,44 @@ redef class MClass
        # Collect all init methods accessible by `self`
        #
        # This include introduced, redefined, inherited inits.
-       fun collect_accessible_inits(view: ModelView): Set[MMethod] do
+       fun collect_accessible_inits(mainmodule: MModule, filter: nullable ModelFilter): Set[MMethod] do
                var set = new HashSet[MMethod]
-               set.add_all(collect_intro_inits(view))
-               set.add_all(collect_redef_inits(view))
-               set.add_all(collect_inherited_inits(view))
+               set.add_all(collect_intro_inits(filter))
+               set.add_all(collect_redef_inits(filter))
+               set.add_all(collect_inherited_inits(mainmodule, filter))
                return set
        end
 
        # Collect all virtual types introduced in `self`
-       fun collect_intro_vts(view: ModelView): Set[MVirtualTypeProp] do
+       fun collect_intro_vts(filter: nullable ModelFilter): Set[MVirtualTypeProp] do
                var res = new HashSet[MVirtualTypeProp]
-               for mproperty in collect_intro_mproperties(view) do
+               for mproperty in collect_intro_mproperties(filter) do
                        if mproperty isa MVirtualTypeProp then res.add(mproperty)
                end
                return res
        end
 
        # Collect all virtual types redefined in `self`
-       fun collect_redef_vts(view: ModelView): Set[MVirtualTypeProp] do
+       fun collect_redef_vts(filter: nullable ModelFilter): Set[MVirtualTypeProp] do
                var res = new HashSet[MVirtualTypeProp]
-               for mproperty in collect_intro_mproperties(view) do
+               for mproperty in collect_intro_mproperties(filter) do
                        if mproperty isa MVirtualTypeProp then res.add(mproperty)
                end
                return res
        end
 
        # Collect all virtual types introduced or redefined in `self`
-       fun collect_local_vts(view: ModelView): Set[MVirtualTypeProp] do
+       fun collect_local_vts(filter: nullable ModelFilter): Set[MVirtualTypeProp] do
                var set = new HashSet[MVirtualTypeProp]
-               set.add_all collect_intro_vts(view)
-               set.add_all collect_redef_vts(view)
+               set.add_all collect_intro_vts(filter)
+               set.add_all collect_redef_vts(filter)
                return set
        end
 
        # Collect all virtual types inherited by `self`
-       fun collect_inherited_vts(view: ModelView): Set[MVirtualTypeProp] do
+       fun collect_inherited_vts(mainmodule: MModule, filter: nullable ModelFilter): Set[MVirtualTypeProp] do
                var res = new HashSet[MVirtualTypeProp]
-               for mproperty in collect_inherited_mproperties(view) do
+               for mproperty in collect_inherited_mproperties(mainmodule, filter) do
                        if mproperty isa MVirtualTypeProp then res.add(mproperty)
                end
                return res
@@ -864,9 +942,9 @@ redef class MClass
        # Collect all virtual types accessible by `self`
        #
        # This include introduced, redefined, inherited virtual types.
-       fun collect_accessible_vts(view: ModelView): Set[MVirtualTypeProp] do
+       fun collect_accessible_vts(mainmodule: MModule, filter: nullable ModelFilter): Set[MVirtualTypeProp] do
                var set = new HashSet[MVirtualTypeProp]
-               for mproperty in collect_accessible_mproperties(view) do
+               for mproperty in collect_accessible_mproperties(mainmodule, filter) do
                        if mproperty isa MVirtualTypeProp then set.add mproperty
                end
                return set
@@ -897,42 +975,41 @@ redef class MClassDef
                return mclassdefs
        end
 
-       redef fun collect_parents(view) do
+       redef fun collect_parents(mainmodule, filter) do
                var res = new HashSet[MENTITY]
                var hierarchy = self.in_hierarchy
                if hierarchy == null then return res
                for parent in hierarchy.direct_greaters do
-                       if parent == self or not view.accept_mentity(parent) then continue
-                       res.add parent
+                       if parent == self then continue
+                       if filter == null or filter.accept_mentity(parent) then res.add parent
                end
                return res
        end
 
-       redef fun collect_children(view) do
+       redef fun collect_children(mainmodule, filter) do
                var res = new HashSet[MENTITY]
                var hierarchy = self.in_hierarchy
                if hierarchy == null then return res
                for child in hierarchy.direct_smallers do
-                       if child == self or not view.accept_mentity(child) then continue
-                       res.add child
+                       if child == self then continue
+                       if filter == null or filter.accept_mentity(child) then res.add child
                end
                return res
        end
 
        # Collect all property definitions in `self`
-       fun collect_mpropdefs(view: ModelView): Set[MPropDef] do
+       fun collect_mpropdefs(filter: nullable ModelFilter): Set[MPropDef] do
                var res = new HashSet[MPropDef]
                for mpropdef in mpropdefs do
-                       if not view.accept_mentity(mpropdef) then continue
-                       res.add mpropdef
+                       if filter == null or filter.accept_mentity(mpropdef) then res.add mpropdef
                end
                return res
        end
 
        # Collect all attribute definitions in `self`
-       fun collect_mattributedefs(view: ModelView): Set[MAttributeDef] do
+       fun collect_mattributedefs(filter: nullable ModelFilter): Set[MAttributeDef] do
                var res = new HashSet[MAttributeDef]
-               for mpropdef in collect_mpropdefs(view) do
+               for mpropdef in collect_mpropdefs(filter) do
                        if not mpropdef isa MAttributeDef then continue
                        res.add mpropdef
                end
@@ -940,9 +1017,9 @@ redef class MClassDef
        end
 
        # Collect all methods definitions in `self`
-       fun collect_mmethoddefs(view: ModelView): Set[MMethodDef] do
+       fun collect_mmethoddefs(filter: nullable ModelFilter): Set[MMethodDef] do
                var res = new HashSet[MMethodDef]
-               for mpropdef in collect_mpropdefs(view) do
+               for mpropdef in collect_mpropdefs(filter) do
                        if not mpropdef isa MMethodDef then continue
                        res.add mpropdef
                end
@@ -950,9 +1027,9 @@ redef class MClassDef
        end
 
        # Collect all virtual types definitions in `self`
-       fun collect_mtypedefs(view: ModelView): Set[MVirtualTypeDef] do
+       fun collect_mtypedefs(filter: nullable ModelFilter): Set[MVirtualTypeDef] do
                var res = new HashSet[MVirtualTypeDef]
-               for mpropdef in collect_mpropdefs(view) do
+               for mpropdef in collect_mpropdefs(filter) do
                        if not mpropdef isa MVirtualTypeDef then continue
                        res.add mpropdef
                end
@@ -960,23 +1037,21 @@ redef class MClassDef
        end
 
        # Collect all property definitions that are introduction in `self`
-       fun collect_intro_mpropdefs(view: ModelView): Set[MPropDef] do
+       fun collect_intro_mpropdefs(filter: nullable ModelFilter): Set[MPropDef] do
                var res = new HashSet[MPropDef]
                for mpropdef in mpropdefs do
                        if not mpropdef.is_intro then continue
-                       if not view.accept_mentity(mpropdef) then continue
-                       res.add mpropdef
+                       if filter == null or filter.accept_mentity(mpropdef) then res.add mpropdef
                end
                return res
        end
 
        # Collect all property definitions that are redefinition in `self`
-       fun collect_redef_mpropdefs(view: ModelView): Set[MPropDef] do
+       fun collect_redef_mpropdefs(filter: nullable ModelFilter): Set[MPropDef] do
                var res = new HashSet[MPropDef]
                for mpropdef in mpropdefs do
                        if mpropdef.is_intro then continue
-                       if not view.accept_mentity(mpropdef) then continue
-                       res.add mpropdef
+                       if filter == null or filter.accept_mentity(mpropdef) then res.add mpropdef
                end
                return res
        end
@@ -992,34 +1067,33 @@ redef class MProperty
        end
 
        # Collect all property definitions of `self`
-       fun collect_mpropdefs(view: ModelView): Set[MPropDef] do
+       fun collect_mpropdefs(filter: nullable ModelFilter): Set[MPropDef] do
                var res = new HashSet[MPropDef]
                for mpropdef in mpropdefs do
-                       if not view.accept_mentity(mpropdef) then continue
-                       res.add mpropdef
+                       if filter == null or filter.accept_mentity(mpropdef) then res.add mpropdef
                end
                return res
        end
 
        # Collect all direct super definitions of `self`
-       redef fun collect_parents(view) do
+       redef fun collect_parents(mainmodule, filter) do
                var res = new HashSet[MENTITY]
                for mpropdef in mpropdefs do
-                       for parent in mpropdef.collect_parents(view) do
-                               if not view.accept_mentity(parent) then continue
-                               res.add parent.mproperty
+                       for parent in mpropdef.collect_parents(mainmodule, filter) do
+                               var mprop = parent.mproperty
+                               if filter == null or filter.accept_mentity(mprop) then res.add mprop
                        end
                end
                return res
        end
 
        # Collection all definitions that have `self` as a direct super definition
-       redef fun collect_children(view) do
+       redef fun collect_children(mainmodule, filter) do
                var res = new HashSet[MENTITY]
                for mpropdef in mpropdefs do
-                       for child in mpropdef.collect_parents(view) do
-                               if not view.accept_mentity(child) then continue
-                               res.add child.mproperty
+                       for child in mpropdef.collect_parents(mainmodule, filter) do
+                               var mprop = child.mproperty
+                               if filter == null or filter.accept_mentity(mprop) then res.add mprop
                        end
                end
                return res
@@ -1070,7 +1144,7 @@ redef class MPropDef
        end
 
        # Collect only the next definition of `self`
-       redef fun collect_parents(view) do
+       redef fun collect_parents(mainmodule, filter) do
                var res = new HashSet[MENTITY]
                var mpropdef = self
                while not mpropdef.is_intro do
@@ -1081,10 +1155,10 @@ redef class MPropDef
        end
 
        # Collect all children definitions that directly depend on `self`
-       redef fun collect_children(view) do
+       redef fun collect_children(mainmodule, filter) do
                var res = new HashSet[MENTITY]
-               for mpropdef in mproperty.collect_mpropdefs(view) do
-                       if mpropdef.collect_parents(view).has(self) then res.add mpropdef
+               for mpropdef in mproperty.collect_mpropdefs(filter) do
+                       if mpropdef.collect_parents(mainmodule, filter).has(self) then res.add mpropdef
                end
                return res
        end
index f8cfb24..d5ece77 100644 (file)
@@ -29,8 +29,7 @@
 #
 # ~~~nitish
 # var index = new ModelIndex
-# var view = new ModelView(model, mainmodule)
-# for mentity in view.mentities do
+# for mentity in model.collect_mentities do
 #      index.index(mentity)
 # end
 # ~~~
@@ -55,8 +54,7 @@
 #
 # ~~~nitish
 # var index = new ModelIndex
-# var view = new ModelView(model, mainmodule)
-# for mentity in view.mentities do
+# for mentity in model.collect_mentities do
 #      # We don't really care about definitions
 #      if mentity isa MClassDef or mentity isa MPropDef then continue
 #      index.index(mentity)
 # ~~~
 module model_index
 
-import model::model_views
+import model::model_collect
 import trees::trie
 
-redef class ModelView
+redef class Model
 
        # Keep a direct link to mentities by full name to speed up `mentity_from_uri`
        var mentities_by_full_name: HashMap[String, MEntity] is lazy do
                var mentities_by_full_name = new HashMap[String, MEntity]
-               for mentity in mentities do
+               for mentity in collect_mentities do
                        mentities_by_full_name[mentity.full_name] = mentity
                end
                return mentities_by_full_name
@@ -144,23 +142,29 @@ redef class ModelView
        # ModelIndex used to perform searches
        var index: ModelIndex is lazy do
                var index = new ModelIndex
-               for mentity in mentities do
+               for mentity in collect_mentities do
                        if mentity isa MClassDef or mentity isa MPropDef then continue
                        index.index mentity
                end
                return index
        end
 
-       redef fun mentities_by_name(name) do
+       redef fun mentities_by_name(name, filter) do
+               var res = new Array[MEntity]
                if index.name_prefixes.has_key(name) then
-                       return index.name_prefixes[name]
+                       for mentity in index.name_prefixes[name] do
+                               if filter == null or filter.accept_mentity(mentity) then
+                                       res.add mentity
+                               end
+                       end
                end
-               return new Array[MEntity]
+               return res
        end
 
-       redef fun mentity_by_full_name(full_name) do
+       redef fun mentity_by_full_name(full_name, filter) do
                if mentities_by_full_name.has_key(full_name) then
-                       return mentities_by_full_name[full_name]
+                       var mentity = mentities_by_full_name[full_name]
+                       if filter == null or filter.accept_mentity(mentity) then return mentity
                end
                return null
        end
@@ -175,7 +179,7 @@ redef class ModelView
 
        # Search mentities based on a `query` string
        #
-       # Lookup the view index for anything matching `query` and return `limit` results.
+       # Lookup the index for anything matching `query` and return `limit` results.
        #
        # The algorithm used is the following:
        # 1- lookup by name prefix
@@ -228,8 +232,7 @@ end
 # ~~~nitish
 # # Build index
 # var index = new ModelIndex
-# var view = new ModelView(model, mainmodule)
-# for mentity in view.mentities do
+# for mentity in model.collect_mentities do
 #      if mentity isa MClassDef or mentity isa MPropDef then continue
 #      index.index(mentity)
 # end
diff --git a/src/model/model_views.nit b/src/model/model_views.nit
deleted file mode 100644 (file)
index cbf3fe2..0000000
+++ /dev/null
@@ -1,246 +0,0 @@
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-module model_views
-
-import model_visitor
-
-# Provide a configurable view to a model.
-#
-# This can be useful when you need to filter some mentities from a model
-# like private or fictive.
-#
-# TODO doc usage
-class ModelView
-       super ModelVisitor
-
-       autoinit(model, mainmodule, filter)
-
-       # The model to view through `self`.
-       var model: Model
-
-       # MModule used to flatten mclass hierarchy
-       var mainmodule: MModule
-
-       # MPackages visible through `self`.
-       var mpackages: Set[MPackage] is lazy do
-               var mpackages = new HashSet[MPackage]
-               for mpackage in model.mpackages do
-                       if not accept_mentity(mpackage) then continue
-                       mpackages.add mpackage
-               end
-               return mpackages
-       end
-
-       # MGroups visible through `self`.
-       var mgroups: Set[MGroup] is lazy do
-               var mgroups = new HashSet[MGroup]
-               for mpackage in mpackages do
-                       for mgroup in mpackage.mgroups do
-                               if not accept_mentity(mgroup) then continue
-                               mgroups.add mgroup
-                       end
-               end
-               return mgroups
-       end
-
-       # MModules visible through `self`.
-       var mmodules: Set[MModule] is lazy do
-               var mmodules = new HashSet[MModule]
-               for mmodule in model.mmodules do
-                       if not accept_mentity(mmodule) then continue
-                       mmodules.add mmodule
-               end
-               return mmodules
-       end
-
-       # MClasses visible through `self`.
-       var mclasses: Set[MClass] is lazy do
-               var mclasses = new HashSet[MClass]
-               for mclass in model.mclasses do
-                       if not accept_mentity(mclass) then continue
-                       mclasses.add mclass
-               end
-               return mclasses
-       end
-
-       # MClassDefs visible through `self`.
-       var mclassdefs: Set[MClassDef] is lazy do
-               var mclassdefs = new HashSet[MClassDef]
-               for mclass in mclasses do
-                       for mclassdef in mclass.mclassdefs do
-                               if not accept_mentity(mclassdef) then continue
-                               mclassdefs.add mclassdef
-                       end
-               end
-               return mclassdefs
-       end
-
-       # MProperties visible through `self`.
-       var mproperties: Set[MProperty] is lazy do
-               var mproperties = new HashSet[MProperty]
-               for mproperty in model.mproperties do
-                       if not accept_mentity(mproperty) then continue
-                       mproperties.add mproperty
-               end
-               return mproperties
-       end
-
-       # MPropdefs visible through `self`.
-       var mpropdefs: Set[MPropDef] is lazy do
-               var mpropdefs = new HashSet[MPropDef]
-               for mproperty in mproperties do
-                       for mpropdef in mproperty.mpropdefs do
-                               if not accept_mentity(mpropdef) then continue
-                               mpropdefs.add mpropdef
-                       end
-               end
-               return mpropdefs
-       end
-
-       # Lists all MEntities visible through `self`.
-       var mentities: Set[MEntity] is lazy do
-               var res = new HashSet[MEntity]
-               res.add_all mpackages
-               res.add_all mgroups
-               res.add_all mmodules
-               res.add_all mclasses
-               res.add_all mclassdefs
-               res.add_all mproperties
-               res.add_all mpropdefs
-               return res
-       end
-
-       # Searches the MEntity that matches `full_name`.
-       fun mentity_by_full_name(full_name: String): nullable MEntity do
-               for mentity in mentities do
-                       if mentity.full_name == full_name then return mentity
-               end
-               return null
-       end
-
-       # Searches the MEntities that matches `full_name`.
-       fun mentities_by_name(name: String): Array[MEntity] do
-               var res = new Array[MEntity]
-               for mentity in mentities do
-                       if mentity.name == name then res.add mentity
-               end
-               return res
-       end
-
-       # Build an concerns tree with from `self`
-       fun to_tree: MEntityTree do
-               var v = new ModelTreeVisitor
-               v.filter = self.filter
-               for mpackage in mpackages do
-                       v.enter_visit(mpackage)
-               end
-               return v.tree
-       end
-
-       # Build the POSet of `mmodules` importation.
-       fun mmodules_poset(mmodules: Set[MModule]): POSet[MModule] do
-               return model.mmodule_importation_hierarchy.sub(mmodules)
-       end
-
-       # Build the POSet of `mclasses` hierarchy.
-       fun mclasses_poset(mainmodule: MModule, mclasses: Set[MClass]): POSet[MClass] do
-               return mainmodule.flatten_mclass_hierarchy.sub(mclasses)
-       end
-end
-
-class LookupNamespaceVisitor
-       super ModelVisitor
-
-       var namespace: String
-
-       private var parts: Array[String] is lazy do return namespace.split_with("::")
-
-       var results = new Array[MEntity]
-
-       redef fun visit(mentity) do mentity.accept_namespace_visitor(self)
-end
-
-class ModelTreeVisitor
-       super ModelVisitor
-
-       var tree = new MEntityTree
-
-       redef fun visit(mentity) do mentity.accept_tree_visitor(self)
-end
-
-redef class MEntity
-       private fun accept_namespace_visitor(v: LookupNamespaceVisitor) do
-               if v.parts.is_empty then return
-               if name != v.parts.first then return
-               v.parts.shift
-               if v.parts.is_empty then
-                       v.results.add self
-                       return
-               end
-               visit_all(v)
-       end
-
-       private fun accept_tree_visitor(v: ModelTreeVisitor) do end
-end
-
-redef class MPackage
-       redef fun accept_tree_visitor(v) do
-               v.tree.add(null, self)
-               visit_all(v)
-       end
-end
-
-redef class MGroup
-       redef fun accept_tree_visitor(v) do
-               var parent = self.parent
-               if parent != null then
-                       v.tree.add(parent, self)
-               else
-                       v.tree.add(mpackage, self)
-               end
-               visit_all(v)
-       end
-end
-
-redef class MModule
-       redef fun accept_tree_visitor(v) do
-               v.tree.add(mgroup, self)
-               visit_all(v)
-       end
-end
-
-redef class MClass
-       # We don't want to collect classes from full namespace.
-       redef fun accept_namespace_visitor(v) do end
-end
-
-redef class MClassDef
-       redef fun accept_tree_visitor(v) do
-               v.tree.add(mmodule, self)
-               visit_all(v)
-       end
-end
-
-redef class MProperty
-       # We don't want to collect properties from full namespace.
-       redef fun accept_namespace_visitor(v) do end
-end
-
-redef class MPropDef
-       redef fun accept_tree_visitor(v) do
-               v.tree.add(mclassdef, self)
-               visit_all(v)
-       end
-end
index 74e0b4c..e19b442 100644 (file)
@@ -62,16 +62,14 @@ var mmodules = mbuilder.parse_full([args.first])
 if mmodules.is_empty then return
 mbuilder.run_phases
 toolcontext.run_global_phases(mmodules)
-var mainmodule = toolcontext.make_main_module(mmodules)
 
 # Build index
 var filters = new ModelFilter(
        private_visibility,
        accept_fictive = false,
        accept_test = false)
-var view = new ModelView(model, mainmodule, filters)
 var index = new ModelIndex
-for mentity in view.mentities do
+for mentity in model.collect_mentities(filters) do
        if mentity isa MClassDef or mentity isa MPropDef then continue
        index.index(mentity)
 end
index 0c44100..afc25c4 100644 (file)
@@ -8,5 +8,5 @@
  * 3: Sys (test_prog::Sys)
  * 3: rpg (test_prog::rpg)
  * 3: test_prog (test_prog>)
- * 3: test_prog (test_prog)
  * 3: test_prog (test_prog::test_prog)
+ * 3: test_prog (test_prog)