neo_doxygen: Move the processing of Doxygen’s names in `doxml`.
[nit.git] / contrib / neo_doxygen / src / model / inner_class.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 # Adds the possibility to define inner classses.
16 module model::inner_class
17
18 import member
19 import class_compound
20
21 # An inner class.
22 class InnerClass
23 super MemberOrInner
24
25 redef type INTRODUCER_TYPE: InnerClassIntroducer
26
27 # The outer class definition.
28 #
29 # Used to correct the short name of the inner class definition when
30 # `put_edges` is called.
31 #
32 # SEE: The notice concerning `name` in `/src/neo.nit`.
33 var outer: ClassDef
34
35 # The `model_id` of the actual inner class (`ClassCompound`).
36 var inner: String
37
38 init do
39 super
40 self.labels.add("MInnerClassDef")
41 end
42
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
46
47 redef fun put_edges do
48 super
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)
55 end
56 end
57
58 # A `MProperty` node for an inner class.
59 class InnerClassIntroducer
60 super MemberIntroducer
61
62 # The definition.
63 var def: InnerClass
64
65 init do
66 super
67 self.labels.add("MInnerClass")
68 end
69
70 redef fun put_edges do
71 super
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)
78 end
79 end
80
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)
85 end
86 end
87
88 # Implements `declare_class`.
89 redef class ClassDef
90
91 # The set of the defined inner classes.
92 #
93 # All `InnerClass` entities registred here are automatically added to the
94 # graph with the `ClassDef`.
95 #
96 # To ensure that the `full_name` of each `InnerClass` entity is correctly
97 # set and that each inner class will be correctly linked, `declare_class`
98 # should be used to add each inner class.
99 var inner_classes: SimpleCollection[InnerClass] = new Array[InnerClass]
100
101 # Declare an inner class.
102 #
103 # Parameters:
104 #
105 # * `id`: `model_id` of the inner class definition.
106 # * `name`: name of the inner class definition.
107 # * `prot`: visibility (proctection).
108 fun declare_class(id: String, name: String, prot: String) do
109 var member = new InnerClass(graph, self, id)
110 member.name = name
111 member.visibility = prot
112 members.add member
113 inner_classes.add member
114 end
115
116 redef fun put_in_graph do
117 super
118 for member in inner_classes do
119 member.put_in_graph
120 end
121 end
122 end