39df50b84fce29ac26df0ae50d7716f69392d8f9
[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 usefull to generalize presentation of entities to the human.
27 abstract class MEntity
28 end
29
30 # A visibility (for modules, class and properties)
31 # Valid visibility are:
32 #
33 # * `intrude_visibility`
34 # * `public_visibility`
35 # * `protected_visibility`
36 # * `none_visibility`
37 #
38 # Note this class is basically an enum.
39 # FIXME: use a real enum once user-defined enums are available
40 class MVisibility
41 super Comparable
42 redef type OTHER: MVisibility
43
44 redef var to_s: String
45
46 private var level: Int
47
48 private init(s: String, level: Int)
49 do
50 self.to_s = s
51 self.level = level
52 end
53
54 # Is self give less visibility than other
55 # none < private < protected < public < intrude
56 redef fun <(other)
57 do
58 return self.level < other.level
59 end
60 end
61
62 fun intrude_visibility: MVisibility do return once new MVisibility("intrude", 5)
63 fun public_visibility: MVisibility do return once new MVisibility("public", 4)
64 fun protected_visibility: MVisibility do return once new MVisibility("protected", 3)
65 fun private_visibility: MVisibility do return once new MVisibility("private", 2)
66 fun none_visibility: MVisibility do return once new MVisibility("none", 1)