rta: store real types in live_cast_type
[nit.git] / src / model / mproject.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 # Modelisation of a Nit project
16 module mproject
17
18 import model_base
19 private import more_collections
20 import poset
21
22 # A Nit project, thas encompass a product
23 class MProject
24 # The name of the project
25 var name: String
26
27 # The model of the project
28 var model: Model
29
30 # The root of the group tree
31 var root: nullable MGroup writable = null
32
33 # The group tree, as a POSet
34 var mgroups = new POSet[MGroup]
35
36 redef fun to_s do return name
37
38 init(name: String, model: Model)
39 do
40 self.name = name
41 self.model = model
42 model.mprojects.add(self)
43 model.mproject_by_name.add_one(name, self)
44 end
45 end
46
47 # A group of modules in a project
48 class MGroup
49 # The name of the group
50 # empty name for a default group in a single-module project
51 var name: String
52
53 # The englobing project
54 var mproject: MProject
55
56 # The parent group if any
57 # see `in_nesting` for more
58 var parent: nullable MGroup
59
60 # fully qualified name
61 fun full_name: String
62 do
63 var p = parent
64 if p == null then return name
65 return "{p.full_name}/{name}"
66 end
67
68 # The group is the group tree on the project (`mproject.mgroups`)
69 # nested groups (children) are smallers
70 # nesting group (see `parent`) is bigger
71 var in_nesting: POSetElement[MGroup]
72
73 # The filepath (usualy a directory) of the group, if any
74 var filepath: nullable String writable
75
76 init (name: String, mproject: MProject, parent: nullable MGroup)
77 do
78 self.name = name
79 self.mproject = mproject
80 self.parent = parent
81 var tree = mproject.mgroups
82 self.in_nesting = tree.add_node(self)
83 if parent != null then
84 tree.add_edge(self, parent)
85 end
86 end
87
88 redef fun to_s do return name
89 end
90
91 redef class Model
92 # projects of the model
93 var mprojects = new Array[MProject]
94
95 # Collections of project grouped by their names
96 private var mproject_by_name: MultiHashMap[String, MProject] = new MultiHashMap[String, MProject]
97
98 # Return all project named `name`
99 # If such a project is not yet loaded, null is returned (instead of an empty array)
100 fun get_mprojects_by_name(name: String): nullable Array[MProject]
101 do
102 if mproject_by_name.has_key(name) then
103 return mproject_by_name[name]
104 else
105 return null
106 end
107 end
108 end