# All known modules
var mmodules: Array[MModule] = new Array[MModule]
- # Module nesting hierarchy.
+ # placebo for old module nesting hierarchy.
# where mainmodule < mainmodule::nestedmodule
+ #
+ # TODO REMOVE, rely on mgroup instead
var mmodule_nesting_hierarchy: POSet[MModule] = new POSet[MModule]
# Full module importation hierarchy including private or nested links.
redef class MGroup
# The loaded modules of this group
var mmodules = new Array[MModule]
+
+ # Placebo stuff to find the owner (module with same name)
+ # null is returned if there is no owner, or if it is not loaded yet
+ fun fuzzy_owner: nullable MModule
+ do
+ for m in mmodules do if m.name == name then return m
+ return null
+ end
end
# A Nit module is usually associated with a Nit source file.
class MModule
+ super MEntity
+
# The model considered
var model: Model
- # The direct nesting module, return null if self is not nested (ie. is a top-level module)
+ # placebo for old module nesting hierarchy
+ # return null if self is not nested (ie. is a top-level module)
+ #
+ # TODO REMOVE, rely on mgroup instead
var direct_owner: nullable MModule
# The group of module in the project if any
# Alias for `name`
redef fun to_s do return self.name
+ # placebo for old module nesting hierarchy
# The view of the module in the `model.mmodule_nesting_hierarchy`
+ #
+ # TODO REMOVE, rely on mgroup instead
var in_nesting: POSetElement[MModule]
# The view of the module in the `model.mmodule_importation_hierarchy`
end
# Create a new empty module and register it to a model
- # `direct_owner` is the direct owner (null if top-level module)
- init(model: Model, direct_owner: nullable MModule, name: String, location: Location)
+ init(model: Model, mgroup: nullable MGroup, name: String, location: Location)
do
self.model = model
self.name = name
model.mmodules_by_name.add_one(name, self)
model.mmodules.add(self)
self.in_nesting = model.mmodule_nesting_hierarchy.add_node(self)
- self.direct_owner = direct_owner
- if direct_owner != null then
- model.mmodule_nesting_hierarchy.add_edge(direct_owner, self)
+ self.mgroup = mgroup
+ if mgroup != null then
+ mgroup.mmodules.add(self)
+ # placebo for old module nesting hierarchy
+ var direct_owner = mgroup.fuzzy_owner
+ if direct_owner == self then
+ # The module is the new owner of its own group, thus adopt the other modules
+ for m in mgroup.mmodules do
+ if m == self then continue
+ m.direct_owner = self
+ model.mmodule_nesting_hierarchy.add_edge(self, m)
+ end
+ # The potential owner is the the fuzzy_owner of the parent group
+ if mgroup.parent != null then direct_owner = mgroup.parent.fuzzy_owner
+ end
+ if direct_owner != self and direct_owner != null then
+ self.direct_owner = direct_owner
+ model.mmodule_nesting_hierarchy.add_edge(direct_owner, self)
+ end
end
self.in_importation = model.mmodule_importation_hierarchy.add_node(self)
end
end
end
- # The first module in the nesting hierarchy to export self as public
- # This function is used to determine the canonical name of modules, classes and properties.
- # REQUIRE: the visibility of all nesting modules is already set.
+ # placebo for old module nesting hierarchy
fun public_owner: nullable MModule
do
- var res = self.direct_owner
- var last = res
- while last != null do
- if last.visibility_for(self) >= public_visibility then res = last
- last = last.direct_owner
- end
+ var mgroup = self.mgroup
+ if mgroup == null then return null
+ mgroup = mgroup.mproject.root
+ if mgroup.mmodules.is_empty then return null
+ var res = mgroup.fuzzy_owner
+ if res == self then return null
return res
end