neo_doxygen: Read the `prot` attribute of the `innerclass` elements.
[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 section_kinds["public-type"] = defaults
56 section_kinds["public-func"] = defaults
57 section_kinds["public-attrib"] = defaults
58 section_kinds["public-slot"] = defaults
59 defaults = new MemberDefaults("public", true, false)
60 section_kinds["public-static-func"] = defaults
61 section_kinds["public-static-attrib"] = defaults
62
63 defaults = new MemberDefaults("protected", false, false)
64 section_kinds["protected-type"] = defaults
65 section_kinds["protected-func"] = defaults
66 section_kinds["protected-attrib"] = defaults
67 section_kinds["protected-slot"] = defaults
68 defaults = new MemberDefaults("protected", true, false)
69 section_kinds["protected-static-func"] = defaults
70 section_kinds["protected-static-attrib"] = defaults
71
72 defaults = new MemberDefaults("package", false, false)
73 section_kinds["package-type"] = defaults
74 section_kinds["package-func"] = defaults
75 section_kinds["package-attrib"] = defaults
76 defaults = new MemberDefaults("package", true, false)
77 section_kinds["package-static-func"] = defaults
78 section_kinds["package-static-attrib"] = defaults
79
80 defaults = new MemberDefaults("private", false, false)
81 section_kinds["private-type"] = defaults
82 section_kinds["private-func"] = defaults
83 section_kinds["private-attrib"] = defaults
84 section_kinds["private-slot"] = defaults
85 defaults = new MemberDefaults("private", true, false)
86 section_kinds["private-static-func"] = defaults
87 section_kinds["private-static-attrib"] = defaults
88
89 defaults = new MemberDefaults("public", true, true)
90 section_kinds["related"] = defaults
91 section_kinds["user-defined"] = defaults
92 end
93
94 redef fun entity: Entity do return compound
95
96 redef fun start_dox_element(local_name: String, atts: Attributes) do
97 if "compoundname" == local_name then
98 text.listen_until(dox_uri, local_name)
99 else if ["innerclass", "innernamespace", "basecompoundref"].has(local_name) then
100 prot = get_optional(atts, "prot", "")
101 text.listen_until(dox_uri, local_name)
102 if "basecompoundref" == local_name then
103 refid = get_optional(atts, "refid", "")
104 virt = get_optional(atts, "virt", "")
105 else
106 refid = get_required(atts, "refid")
107 end
108 else if "memberdef" == local_name then
109 read_member(atts)
110 else if local_name == "sectiondef" then
111 member_defaults = section_kinds[get_required(atts, "kind")]
112 if member_defaults.is_special then
113 super # TODO
114 end
115 else if "param" == local_name then
116 param_listener.listen_until(dox_uri, local_name)
117 else if "templateparamlist" != local_name then
118 super
119 end
120 end
121
122 redef fun end_dox_element(local_name: String) do
123 if local_name == "compoundname" then
124 compound.full_name = text.to_s
125 else if local_name == "innerclass" then
126 compound.declare_class(refid, text.to_s, prot)
127 else if local_name == "innernamespace" then
128 compound.declare_namespace(refid, text.to_s)
129 else if "memberdef" == local_name then
130 if not (memberdef.member isa UnknownMember) then
131 compound.declare_member(memberdef.member)
132 end
133 else if local_name == "basecompoundref" then
134 compound.declare_super(refid, text.to_s, prot, virt)
135 else if "param" == local_name and compound isa ClassCompound then
136 compound.as(ClassCompound).add_type_parameter(param_listener.parameter)
137 else
138 super
139 end
140 end
141
142 private fun read_member(atts: Attributes) do
143 var kind = get_required(atts, "kind")
144
145 create_member(kind)
146 memberdef.member.model_id = get_required(atts, "id")
147 memberdef.member.visibility = get_optional(atts, "prot",
148 member_defaults.visibility)
149 end
150
151 private fun create_member(kind: String) do
152 if kind == "variable" then
153 memberdef.member = new Attribute(compound.graph)
154 else if kind == "function" then
155 memberdef.member = new Method(compound.graph)
156 else
157 memberdef.member = new UnknownMember(compound.graph)
158 noop.listen_until(dox_uri, "memberdef")
159 return
160 end
161 memberdef.listen_until(dox_uri, "memberdef")
162 end
163 end
164
165 # Default attributes for members in the current section.
166 private class MemberDefaults
167 var visibility: String
168 var is_static: Bool
169 var is_special: Bool
170 end