13da7babaaeabc14207ac428be4bae464faf3f9c
1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # `compounddef` element reading.
16 module doxml
::compounddef
19 import more_collections
21 # Processes the content of a `compounddef` element.
22 class CompoundDefListener
23 super EntityDefListener
25 # The defined compound.
26 var compound
: Compound is writable, noinit
28 private var memberdef
: MemberDefListener is noinit
29 private var param_listener
: TypeParamListener is noinit
31 # Default attributes for members in the current section.
32 private var member_defaults
: MemberDefaults is noinit
34 # For each section kind, default attributes for member in that section.
35 private var section_kinds
: DefaultMap[String, MemberDefaults] is noinit
38 # Attributes of the current `<basecompoundref>` element.
40 private var refid
= ""
47 var defaults
= new MemberDefaults("public", false, false)
49 memberdef
= new MemberDefListener(reader
, self)
50 param_listener
= new TypeParamListener(reader
, self)
52 member_defaults
= defaults
53 section_kinds
= new DefaultMap[String, MemberDefaults](defaults
)
56 section_kinds
["public-type"] = defaults
57 section_kinds
["public-func"] = defaults
58 section_kinds
["public-attrib"] = defaults
59 section_kinds
["public-slot"] = defaults
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
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
82 defaults
= new MemberDefaults("protected", true, false)
83 section_kinds
["protected-static-func"] = defaults
84 section_kinds
["protected-static-attrib"] = defaults
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
92 defaults
= new MemberDefaults("package", true, false)
93 section_kinds
["package-static-func"] = defaults
94 section_kinds
["package-static-attrib"] = defaults
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
103 defaults
= new MemberDefaults("private", true, false)
104 section_kinds
["private-static-func"] = defaults
105 section_kinds
["private-static-attrib"] = defaults
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.
115 redef fun entity
: Entity do return compound
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", "")
127 refid
= get_required
(atts
, "refid")
129 else if "memberdef" == local_name
then
131 else if "sectiondef" == local_name
then
132 member_defaults
= section_kinds
[get_required
(atts
, "kind")]
133 if member_defaults
.is_special
then
136 else if "param" == local_name
then
137 param_listener
.listen_until
(dox_uri
, local_name
)
138 else if "templateparamlist" != local_name
then
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
)
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
)
163 private fun read_member
(atts
: Attributes) do
164 var kind
= get_required
(atts
, "kind")
167 memberdef
.member
.model_id
= get_required
(atts
, "id")
168 memberdef
.member
.visibility
= get_optional
(atts
, "prot",
169 member_defaults
.visibility
)
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
)
178 memberdef
.member
= new UnknownMember(compound
.graph
)
179 noop
.listen_until
(dox_uri
, "memberdef")
182 memberdef
.listen_until
(dox_uri
, "memberdef")
186 # Default attributes for members in the current section.
187 private class MemberDefaults
188 var visibility
: String