1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Modelisation of a Nit project
19 private import more_collections
23 # A Nit project, that encompass a product
27 # The name of the project
28 redef var name
: String
30 # The model of the project
31 redef var model
: Model
33 # The root of the group tree
34 var root
: nullable MGroup = null is writable
36 # The group tree, as a POSet
37 var mgroups
= new POSet[MGroup]
39 redef fun to_s
do return name
43 model
.mprojects
.add
(self)
44 model
.mproject_by_name
.add_one
(name
, self)
47 # MProject are always roots of the concerns hierarchy
48 redef fun parent_concern
do return null
50 redef fun mdoc_or_fallback
52 if mdoc
!= null then return mdoc
53 return root
.mdoc_or_fallback
57 # A group of modules in a project
61 # The name of the group
62 # empty name for a default group in a single-module project
63 redef var name
: String
65 # The enclosing project
66 var mproject
: MProject
68 # The parent group if any
69 # see `in_nesting` for more
70 var parent
: nullable MGroup
72 # fully qualified name
76 if p
== null then return name
77 return "{p.full_name}/{name}"
80 # The group is the group tree on the project (`mproject.mgroups`)
81 # nested groups (children) are smaller
82 # nesting group (see `parent`) is bigger
83 var in_nesting
: POSetElement[MGroup] is noinit
85 # Is `self` the root of its project?
86 fun is_root
: Bool do return mproject
.root
== self
88 # The filepath (usually a directory) of the group, if any
89 var filepath
: nullable String = null is writable
93 var tree
= mproject
.mgroups
94 self.in_nesting
= tree
.add_node
(self)
95 var parent
= self.parent
96 if parent
!= null then
97 tree
.add_edge
(self, parent
)
101 redef fun model
do return mproject
.model
103 redef fun parent_concern
do
104 if not is_root
then return parent
108 redef fun to_s
do return name
112 # projects of the model
113 var mprojects
= new Array[MProject]
115 # Collections of project grouped by their names
116 private var mproject_by_name
= new MultiHashMap[String, MProject]
118 # Return all project named `name`
119 # If such a project is not yet loaded, null is returned (instead of an empty array)
120 fun get_mprojects_by_name
(name
: String): nullable Array[MProject]
122 if mproject_by_name
.has_key
(name
) then
123 return mproject_by_name
[name
]