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