Each MProject, MGroup and MModules represents a documentable concern.
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>
# A Nit module is usually associated with a Nit source file.
class MModule
- super MEntity
+ super MConcern
# The model considered
var model: Model
abort
end
end
+
+ redef fun parent_concern do return mgroup
end
import location
import mmodule
import mdoc
+import ordered_tree
private import more_collections
redef class Model
# The only null type
var null_type: MNullType = new MNullType(self)
+
+ # Build an ordered tree with from `concerns`
+ fun concerns_tree(mconcerns: Collection[MConcern]): ConcernsTree do
+ var seen = new HashSet[MConcern]
+ var res = new ConcernsTree
+
+ var todo = new Array[MConcern]
+ todo.add_all mconcerns
+
+ while not todo.is_empty do
+ var c = todo.pop
+ if seen.has(c) then continue
+ var pc = c.parent_concern
+ if pc == null then
+ res.add(null, c)
+ else
+ res.add(pc, c)
+ todo.add(pc)
+ end
+ seen.add(c)
+ end
+
+ return res
+ end
+end
+
+# An OrderedTree that can be easily refined for display purposes
+class ConcernsTree
+ super OrderedTree[MConcern]
end
redef class MModule
fun name: String is abstract
end
+# Something that represents a concern
+abstract class MConcern
+ super MEntity
+ # The concern that contains `self` or null if `self` is the root of the concern hierarchy
+ fun parent_concern: nullable MConcern is abstract
+end
+
# A visibility (for modules, class and properties)
# Valid visibility are:
#
# A Nit project, thas encompass a product
class MProject
- super MEntity
+ super MConcern
# The name of the project
redef var name: String
model.mprojects.add(self)
model.mproject_by_name.add_one(name, self)
end
+
+ # MProject are always roots of the concerns hierarchy
+ redef fun parent_concern do return null
end
# A group of modules in a project
class MGroup
- super MEntity
+ super MConcern
# The name of the group
# empty name for a default group in a single-module project
# nesting group (see `parent`) is bigger
var in_nesting: POSetElement[MGroup]
+ # Is `self` the root of its project?
+ fun is_root: Bool do return mproject.root == self
+
# The filepath (usualy a directory) of the group, if any
var filepath: nullable String writable
end
end
+ redef fun parent_concern do
+ if not is_root then return parent
+ return mproject
+ end
+
redef fun to_s do return name
end