src: update most tools to new constructors
[nit.git] / src / model / model_base.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2012 Jean Privat <jean@pryen.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # The abstract concept of model and related common things
18 module model_base
19
20 # The container class of a Nit object-oriented model.
21 # A model knows modules, classes and properties and can retrieve them.
22 class Model
23 end
24
25 # A named and possibly documented entity in the model.
26 # This class is useful to generalize presentation of entities to the human.
27 abstract class MEntity
28 # The short (unqualified) name of this model entity
29 fun name: String is abstract
30
31 # A Model Entity has a direct link to its model
32 fun model: Model is abstract
33 end
34
35 # Something that represents a concern
36 abstract class MConcern
37 super MEntity
38 # The concern that contains `self` or null if `self` is the root of the concern hierarchy
39 fun parent_concern: nullable MConcern is abstract
40 end
41
42 # A visibility (for modules, class and properties)
43 # Valid visibility are:
44 #
45 # * `intrude_visibility`
46 # * `public_visibility`
47 # * `protected_visibility`
48 # * `none_visibility`
49 # * `private_visiblity`
50 #
51 # Note this class is basically an enum.
52 # FIXME: use a real enum once user-defined enums are available
53 class MVisibility
54 super Comparable
55 redef type OTHER: MVisibility
56
57 redef var to_s: String
58
59 private var level: Int
60
61 # TODO: private init because enumeration.
62
63 # Is self give less visibility than other
64 # none < private < protected < public < intrude
65 redef fun <(other)
66 do
67 return self.level < other.level
68 end
69 end
70
71 # The visibility level `intrude`
72 fun intrude_visibility: MVisibility do return once new MVisibility("intrude", 5)
73 # The visibility level `public`
74 fun public_visibility: MVisibility do return once new MVisibility("public", 4)
75 # The visibility level `protected`
76 fun protected_visibility: MVisibility do return once new MVisibility("protected", 3)
77 # The visibility level `private`
78 fun private_visibility: MVisibility do return once new MVisibility("private", 2)
79 # The visibility level `none` (no visibility)
80 fun none_visibility: MVisibility do return once new MVisibility("none", 1)