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 # Adds the possibility to define inner classses.
16 module model
::inner_class
25 redef type INTRODUCER_TYPE: InnerClassIntroducer
27 # The outer class definition.
29 # Used to correct the short name of the inner class definition when
30 # `put_edges` is called.
32 # SEE: The notice concerning `name` in `/src/neo.nit`.
35 # The `model_id` of the actual inner class (`ClassCompound`).
40 self.labels
.add
("MInnerClassDef")
43 redef fun is_intro
do return true
44 redef fun create_introducer
do return new InnerClassIntroducer(graph
, self)
45 redef fun resolve_introducer
do return introducer
47 redef fun put_edges
do
49 var inner
= graph
.by_id
[self.inner
]
50 assert inner
isa ClassCompound
51 var inner_def
= inner
.class_def
52 # Correct the short name of `inner` to avoid name collisions in a module.
53 inner_def
.name
= "{outer.name}{ns_separator}{name}"
54 graph
.add_edge
(self, "NESTS", inner_def
)
58 # A `MProperty` node for an inner class.
59 class InnerClassIntroducer
60 super MemberIntroducer
67 self.labels
.add
("MInnerClass")
70 redef fun put_edges
do
72 var inner
= graph
.by_id
[def
.inner
]
73 assert inner
isa ClassCompound
74 var outer
= def
.outer
.class_compound
75 # Correct the short name of `inner` to avoid name collisions in a module.
76 inner
.name
= "{outer.name}{ns_separator}{name}"
77 graph
.add_edge
(self, "NESTS", inner
)
81 # Implements `declare_class`.
82 redef class ClassCompound
83 redef fun declare_class
(id
, name
, prot
) do
84 class_def
.declare_class
(id
, name
, prot
)
88 # Implements `declare_class`.
91 # The set of the defined inner classes.
93 # All `InnerClass` entities registred here are automatically added to the
94 # graph with the `ClassDef`.
96 # To ensure that each inner class will be correctly linked,
97 # `declare_class` should be used to add each inner class.
98 var inner_classes
: SimpleCollection[InnerClass] = new Array[InnerClass]
100 # Declare an inner class.
104 # * `id`: `model_id` of the inner class definition.
105 # * `name`: name of the inner class definition.
106 # * `prot`: visibility (proctection).
107 fun declare_class
(id
: String, name
: String, prot
: String) do
108 var member
= new InnerClass(graph
, self, id
)
110 member
.visibility
= prot
112 inner_classes
.add member
115 redef fun put_in_graph
do
117 for member
in inner_classes
do