neo_doxygen: Move the processing of Doxygen’s names in `doxml`.
[nit.git] / contrib / neo_doxygen / src / doxml / compounddef.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 # `compounddef` element reading.
16 module doxml::compounddef
17
18 import memberdef
19 import doxyname
20 import more_collections
21
22 # Processes the content of a `compounddef` element.
23 class CompoundDefListener
24 super EntityDefListener
25
26 # The defined compound.
27 var compound: Compound is writable, noinit
28
29 private var memberdef: MemberDefListener is noinit
30 private var param_listener: TypeParamListener is noinit
31
32 # Default attributes for members in the current section.
33 private var member_defaults: MemberDefaults is noinit
34
35 # For each section kind, default attributes for member in that section.
36 private var section_kinds: DefaultMap[String, MemberDefaults] is noinit
37
38
39 # Attributes of the current `<basecompoundref>` element.
40
41 private var refid = ""
42 private var prot = ""
43 private var virt = ""
44
45
46 init do
47 super
48 var defaults = new MemberDefaults("public", false, false)
49
50 memberdef = new MemberDefListener(reader, self)
51 param_listener = new TypeParamListener(reader, self)
52
53 member_defaults = defaults
54 section_kinds = new DefaultMap[String, MemberDefaults](defaults)
55
56 # public
57 section_kinds["public-type"] = defaults
58 section_kinds["public-func"] = defaults
59 section_kinds["public-attrib"] = defaults
60 section_kinds["public-slot"] = defaults
61 # public static
62 defaults = new MemberDefaults("public", true, false)
63 section_kinds["public-static-func"] = defaults
64 section_kinds["public-static-attrib"] = defaults
65 # Not scoped => public static
66 section_kinds["signal"] = defaults
67 section_kinds["dcop-func"] = defaults
68 section_kinds["property"] = defaults
69 section_kinds["event"] = defaults
70 section_kinds["define"] = defaults
71 section_kinds["typedef"] = defaults
72 section_kinds["enum"] = defaults
73 section_kinds["func"] = defaults
74 section_kinds["var"] = defaults
75
76 # protected
77 defaults = new MemberDefaults("protected", false, false)
78 section_kinds["protected-type"] = defaults
79 section_kinds["protected-func"] = defaults
80 section_kinds["protected-attrib"] = defaults
81 section_kinds["protected-slot"] = defaults
82 # protected static
83 defaults = new MemberDefaults("protected", true, false)
84 section_kinds["protected-static-func"] = defaults
85 section_kinds["protected-static-attrib"] = defaults
86
87 # package
88 defaults = new MemberDefaults("package", false, false)
89 section_kinds["package-type"] = defaults
90 section_kinds["package-func"] = defaults
91 section_kinds["package-attrib"] = defaults
92 # package static
93 defaults = new MemberDefaults("package", true, false)
94 section_kinds["package-static-func"] = defaults
95 section_kinds["package-static-attrib"] = defaults
96
97 # private
98 defaults = new MemberDefaults("private", false, false)
99 section_kinds["private-type"] = defaults
100 section_kinds["private-func"] = defaults
101 section_kinds["private-attrib"] = defaults
102 section_kinds["private-slot"] = defaults
103 # private static
104 defaults = new MemberDefaults("private", true, false)
105 section_kinds["private-static-func"] = defaults
106 section_kinds["private-static-attrib"] = defaults
107
108 # Special sections.
109 # TODO Do something these sections.
110 defaults = new MemberDefaults("public", true, true)
111 section_kinds["related"] = defaults
112 section_kinds["user-defined"] = defaults
113 # TODO Determine what `friend` and `prototype` mean.
114 end
115
116 redef fun entity: Entity do return compound
117
118 redef fun start_dox_element(local_name: String, atts: Attributes) do
119 if "compoundname" == local_name then
120 text.listen_until(dox_uri, local_name)
121 else if ["innerclass", "innernamespace", "basecompoundref"].has(local_name) then
122 prot = get_optional(atts, "prot", "")
123 text.listen_until(dox_uri, local_name)
124 if "basecompoundref" == local_name then
125 refid = get_optional(atts, "refid", "")
126 virt = get_optional(atts, "virt", "")
127 else
128 refid = get_required(atts, "refid")
129 end
130 else if "memberdef" == local_name then
131 read_member(atts)
132 else if "sectiondef" == local_name then
133 member_defaults = section_kinds[get_required(atts, "kind")]
134 if member_defaults.is_special then
135 super # TODO
136 end
137 else if "param" == local_name then
138 param_listener.listen_until(dox_uri, local_name)
139 else if "templateparamlist" != local_name then
140 super
141 end
142 end
143
144 redef fun end_dox_element(local_name: String) do
145 if "compoundname" == local_name then
146 compound.doxyname = text.to_s
147 else if "innerclass" == local_name then
148 compound.doxygen_declare_class(refid, text.to_s, prot)
149 else if "innernamespace" == local_name then
150 compound.declare_namespace(refid, text.to_s)
151 else if "memberdef" == local_name then
152 if not (memberdef.member isa UnknownMember) then
153 compound.declare_member(memberdef.member)
154 end
155 else if "basecompoundref" == local_name then
156 compound.declare_super(refid, text.to_s, prot, virt)
157 else if "param" == local_name and compound isa ClassCompound then
158 compound.as(ClassCompound).add_type_parameter(param_listener.parameter)
159 else
160 super
161 end
162 end
163
164 private fun read_member(atts: Attributes) do
165 var kind = get_required(atts, "kind")
166
167 create_member(kind)
168 memberdef.member.model_id = get_required(atts, "id")
169 memberdef.member.visibility = get_optional(atts, "prot",
170 member_defaults.visibility)
171 end
172
173 private fun create_member(kind: String) do
174 if kind == "variable" then
175 memberdef.member = new Attribute(compound.graph)
176 else if kind == "function" then
177 memberdef.member = new Method(compound.graph)
178 else
179 memberdef.member = new UnknownMember(compound.graph)
180 noop.listen_until(dox_uri, "memberdef")
181 return
182 end
183 memberdef.listen_until(dox_uri, "memberdef")
184 end
185 end
186
187 # Default attributes for members in the current section.
188 private class MemberDefaults
189 var visibility: String
190 var is_static: Bool
191 var is_special: Bool
192 end