model: promote `full_name` to MEntity
[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 #
30 # The short-name is based from the identifiers used to declare or denote the entity.
31 # It is usually globally ambiguous but is often enough in a precise local context.
32 #
33 # It is suitable to use the short-name in message to the user.
34 # However, special care must be used in case of potential ambiguities or name conflict.
35 fun name: String is abstract
36
37 # A fully-qualified name of this model entity.
38 #
39 # The full-name is based on the short name and is usually prefixed by the name of an outer entity.
40 # Usually the quad (`::`) is used to separate the different names.
41 #
42 # The full-name is expected to be unique and unambiguous in lawful Nit models for the same kind of entity.
43 #
44 # It is often suitable to use it in message to the user.
45 # However, some full-name could be long and verbose,
46 #
47 # See the specific implementation in subclasses for details.
48 fun full_name: String is abstract
49
50 # A Model Entity has a direct link to its model
51 fun model: Model is abstract
52 end
53
54 # Something that represents a concern
55 abstract class MConcern
56 super MEntity
57 # The concern that contains `self` or null if `self` is the root of the concern hierarchy
58 fun parent_concern: nullable MConcern is abstract
59 end
60
61 # A visibility (for modules, class and properties)
62 # Valid visibility are:
63 #
64 # * `intrude_visibility`
65 # * `public_visibility`
66 # * `protected_visibility`
67 # * `none_visibility`
68 # * `private_visiblity`
69 #
70 # Note this class is basically an enum.
71 # FIXME: use a real enum once user-defined enums are available
72 class MVisibility
73 super Comparable
74 redef type OTHER: MVisibility
75
76 redef var to_s: String
77
78 private var level: Int
79
80 # TODO: private init because enumeration.
81
82 # Is self give less visibility than other
83 # none < private < protected < public < intrude
84 redef fun <(other)
85 do
86 return self.level < other.level
87 end
88 end
89
90 # The visibility level `intrude`
91 fun intrude_visibility: MVisibility do return once new MVisibility("intrude", 5)
92 # The visibility level `public`
93 fun public_visibility: MVisibility do return once new MVisibility("public", 4)
94 # The visibility level `protected`
95 fun protected_visibility: MVisibility do return once new MVisibility("protected", 3)
96 # The visibility level `private`
97 fun private_visibility: MVisibility do return once new MVisibility("private", 2)
98 # The visibility level `none` (no visibility)
99 fun none_visibility: MVisibility do return once new MVisibility("none", 1)