+ 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(filter: nullable ModelFilter): HashSet[MClass] do
+ var res = new HashSet[MClass]
+ 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(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 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
+end
+
+redef class MPackage
+
+ redef fun collect_modifiers do return super + ["package"]
+
+ # Collect all packages directly imported by `self`
+ redef fun collect_parents(mainmodule, filter) do
+ var res = new HashSet[MENTITY]
+ for mgroup in mgroups do
+ for parent in mgroup.collect_parents(mainmodule, filter) do
+ var mpackage = parent.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(mainmodule, filter) do
+ var res = new HashSet[MENTITY]
+ 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(filter: nullable ModelFilter): HashSet[MGroup] do
+ var res = new HashSet[MGroup]
+ for mgroup in mgroups do
+ 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(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(filter)
+ return res
+ end
+
+ # Collect all modules contained in `self`
+ fun collect_all_mmodules(filter: nullable ModelFilter): HashSet[MModule] do
+ var res = new HashSet[MModule]
+ 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(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(filter)
+ return res
+ end
+
+ # Collect all classes introduced in `self`
+ 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(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(filter: nullable ModelFilter): Set[MClass] do
+ var res = new HashSet[MClass]
+ for mgroup in mgroups do
+ 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(filter: nullable ModelFilter): HashSet[MProperty] do
+ var res = new HashSet[MProperty]
+ for mgroup in mgroups do
+ 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(filter: nullable ModelFilter): HashSet[MProperty] do
+ var res = new HashSet[MProperty]
+ for mgroup in mgroups do
+ 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(filter: nullable ModelFilter): Set[MAttribute] do
+ var res = new HashSet[MAttribute]
+ for mgroup in mgroups do
+ 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(filter: nullable ModelFilter): Set[MMethod] do
+ var res = new HashSet[MMethod]
+ for mgroup in mgroups do
+ for mmodule in collect_all_mmodules(filter) do
+ res.add_all mmodule.collect_intro_inits(filter)
+ end
+ end
+ return res
+ end
+
+ # Collect all methods introduced in `self` excluding inits
+ #
+ # See `collect_intro_inits`.
+ 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(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(filter: nullable ModelFilter): Set[MVirtualTypeProp] do
+ var res = new HashSet[MVirtualTypeProp]
+ for mgroup in mgroups do
+ for mmodule in collect_all_mmodules(filter) do
+ res.add_all mmodule.collect_intro_vts(filter)
+ end
+ end
+ return res
+ end
+end
+
+redef class MGroup
+
+ redef fun collect_modifiers do return super + ["group"]
+
+ # Collect all groups directly import by `self`
+ redef fun collect_parents(mainmodule, filter) do
+ var res = new HashSet[MENTITY]
+ for mmodule in mmodules do
+ for parent in mmodule.collect_parents(mainmodule, filter) do
+ var mgroup = parent.mgroup
+ if mgroup == null or mgroup == self then continue
+ 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(mainmodule, filter) do
+ var res = new HashSet[MENTITY]
+ 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(filter: nullable ModelFilter): HashSet[MENTITY] do
+ var res = new HashSet[MENTITY]
+ for mgroup in in_nesting.direct_smallers do
+ 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(filter: nullable ModelFilter): HashSet[MModule] do
+ var res = new HashSet[MModule]
+ 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(filter: nullable ModelFilter): HashSet[MModule] do
+ var res = new HashSet[MModule]
+ for mmodule in mmodules do
+ if filter == null or filter.accept_mentity(mmodule) then res.add(mmodule)
+ end
+ return res
+ end
+end
+
+redef class MModule
+
+ redef fun collect_modifiers do return super + ["module"]
+
+ # Collect all modules directly imported by `self`
+ redef fun collect_ancestors(mainmodule, filter) do
+ var res = new HashSet[MENTITY]