import poset
import location
-import model_base
+import mproject
private import more_collections
# The container class of a Nit object-oriented model.
end
end
+redef class MGroup
+ # The loaded modules of this group
+ var mmodules = new Array[MModule]
+end
+
# A Nit module is usually associated with a Nit source file.
-# Modules can be nested (see `direct_owner`, `public_owner`, and `in_nesting`)
class MModule
# The model considered
var model: Model
# The direct nesting module, return null if self is not nested (ie. is a top-level module)
var direct_owner: nullable MModule
+ # The group of module in the project if any
+ var mgroup: nullable MGroup
+
# The short name of the module
var name: String
var in_importation: POSetElement[MModule]
# The canonical name of the module
- # Example: `"owner::name"`
+ # Example: `"project::name"`
fun full_name: String
do
- var owner = self.public_owner
- if owner == null then
+ var mgroup = self.mgroup
+ if mgroup == null or mgroup.mproject.name == self.name then
return self.name
else
- return "{owner.full_name}::{self.name}"
+ return "{mgroup.mproject.name}::{self.name}"
end
end
--- /dev/null
+# 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.
+
+# Modelisation of a Nit project
+module mproject
+
+import model_base
+private import more_collections
+import poset
+
+# A Nit project, thas encompass a product
+class MProject
+ # The name of the project
+ var name: String
+
+ # The model of the project
+ var model: Model
+
+ # The root of the group tree
+ var root: nullable MGroup writable = null
+
+ # The group tree, as a POSet
+ var mgroups = new POSet[MGroup]
+
+ redef fun to_s do return name
+
+ init(name: String, model: Model)
+ do
+ self.name = name
+ self.model = model
+ model.mprojects.add(self)
+ model.mproject_by_name.add_one(name, self)
+ end
+end
+
+# A group of modules in a project
+class MGroup
+ # The name of the group
+ # empty name for a default group in a single-module project
+ var name: String
+
+ # The englobing project
+ var mproject: MProject
+
+ # The parent group if any
+ # see `in_nesting` for more
+ var parent: nullable MGroup
+
+ # fully qualified name
+ fun full_name: String
+ do
+ var p = parent
+ if p == null then return name
+ return "{p.full_name}/{name}"
+ end
+
+ # The group is the group tree on the project (`mproject.mgroups`)
+ # nested groups (children) are smallers
+ # nesting group (see `parent`) is bigger
+ var in_nesting: POSetElement[MGroup]
+
+ # The filepath (usualy a directory) of the group, if any
+ var filepath: nullable String writable
+
+ init (name: String, mproject: MProject, parent: nullable MGroup)
+ do
+ self.name = name
+ self.mproject = mproject
+ self.parent = parent
+ var tree = mproject.mgroups
+ self.in_nesting = tree.add_node(self)
+ if parent != null then
+ tree.add_edge(self, parent)
+ end
+ end
+
+ redef fun to_s do return name
+end
+
+redef class Model
+ # projects of the model
+ var mprojects = new Array[MProject]
+
+ # Collections of project grouped by their names
+ private var mproject_by_name: MultiHashMap[String, MProject] = new MultiHashMap[String, MProject]
+
+ # Return all project named `name`
+ # If such a project is not yet loaded, null is returned (instead of an empty array)
+ fun get_mprojects_by_name(name: String): nullable Array[MProject]
+ do
+ if mproject_by_name.has_key(name) then
+ return mproject_by_name[name]
+ else
+ return null
+ end
+ end
+end