neo_doxygen: Include namespaces’ members.
[nit.git] / contrib / neo_doxygen / src / model / namespace_members.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 # Add support for namespace’s members.
16 module model::namespace_members
17
18 import class_compound
19 import member
20
21 redef class Namespace
22 # The class that contains the namespace’s direct members.
23 #
24 # Left `null` for the root namespace and for any namespace with no direct
25 # member. Automatically put in the graph with the namespace.
26 #
27 # Note: In the graph, the `self_class` not linked directly to the namespace.
28 # This is the role of the modules implicitly created by `FileCompound`s to
29 # link a namespace to its `self_class`.
30 #
31 # SEE: `declare_member`
32 var self_class: nullable SelfClass = null
33
34 # Add the specified member as a direct children of the namespace.
35 redef fun declare_member(member) do
36 if self_class == null then self_class = new SelfClass(graph, self)
37 self_class.as(not null).declare_member(member)
38 end
39
40 redef fun full_name=(full_name) do
41 super
42 var self_class = self.self_class
43 if self_class isa SelfClass then self_class.update_name
44 end
45
46 redef fun parent_name=(parent_name) do
47 super
48 var self_class = self.self_class
49 if self_class isa SelfClass then self_class.update_name
50 end
51
52 redef fun put_in_graph do
53 super
54 var self_class = self.self_class
55 if self_class isa SelfClass then self_class.put_in_graph
56 end
57 end
58
59 redef class RootNamespace
60 redef fun declare_member(member) do
61 assert false else
62 # TODO Check how Doxygen modelize member of the root namespace.
63 # Note: Doxygen does not modelize the root namespace.
64 sys.stderr.write "The addition of a member to the root namespace is not supported yet."
65 end
66 end
67 end
68
69 # A class that contains a namespace’s direct members.
70 class SelfClass
71 super ClassCompound
72
73 # The namespace of the members
74 var namespace: Namespace
75
76 init do
77 super
78 name = "(self)"
79 update_name
80 end
81
82 # Update the `full_name`.
83 #
84 # Update the parent name to the `full_name` of the namespace.
85 private fun update_name do parent_name = namespace.full_name
86 end