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
# The short name of the class
# In Nit, the name of a class cannot evolve in refinements
- var name: String
+ redef var name: String
# The canonical name of the class
# Example: `"owner::module::MyClass"`
self.to_s = "{mmodule}#{mclass}"
end
+ # Actually the name of the `mclass`
+ redef fun name do return mclass.name
+
# All declared super-types
# FIXME: quite ugly but not better idea yet
var supertypes: Array[MClassType] = new Array[MClassType]
var intro_mclassdef: MClassDef
# The (short) name of the property
- var name: String
+ redef var name: String
# The canonical name of the property
# Example: "owner::my_module::MyClass::my_method"
self.to_s = "{mclassdef}#{mproperty}"
end
+ # Actually the name of the `mproperty`
+ redef fun name do return mproperty.name
+
# Internal name combining the module, the class and the property
# Example: "mymodule#MyClass#mymethod"
redef var to_s: String
# A named and possibly documented entity in the model.
# This class is usefull to generalize presentation of entities to the human.
abstract class MEntity
+ # The short (unqualified) name of this model entity
+ 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)
# A Nit project, thas encompass a product
class MProject
- super MEntity
+ super MConcern
# The name of the project
- var name: String
+ redef var name: String
# The model of the project
var model: Model
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
- var name: String
+ redef var name: String
# The englobing project
var mproject: MProject
# 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