4cd42ca9687e6e17718adeaa1ed2808ca8cfa08d
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 var compound
: Compound is writable, noinit
26 private var memberdef
: MemberDefListener is noinit
27 private var param_listener
: TypeParamListener is noinit
29 # Default attributes for members in the current section.
30 private var member_defaults
: MemberDefaults is noinit
32 # For each section kind, default attributes for member in that section.
33 private var section_kinds
: DefaultMap[String, MemberDefaults] is noinit
36 # Attributes of the current `<basecompoundref>` element.
38 private var refid
= ""
45 var defaults
= new MemberDefaults("public", false, false)
47 memberdef
= new MemberDefListener(reader
, self)
48 param_listener
= new TypeParamListener(reader
, self)
50 member_defaults
= defaults
51 section_kinds
= new DefaultMap[String, MemberDefaults](defaults
)
53 section_kinds
["public-type"] = defaults
54 section_kinds
["public-func"] = defaults
55 section_kinds
["public-attrib"] = defaults
56 section_kinds
["public-slot"] = defaults
57 defaults
= new MemberDefaults("public", true, false)
58 section_kinds
["public-static-func"] = defaults
59 section_kinds
["public-static-attrib"] = defaults
61 defaults
= new MemberDefaults("protected", false, false)
62 section_kinds
["protected-type"] = defaults
63 section_kinds
["protected-func"] = defaults
64 section_kinds
["protected-attrib"] = defaults
65 section_kinds
["protected-slot"] = defaults
66 defaults
= new MemberDefaults("protected", true, false)
67 section_kinds
["protected-static-func"] = defaults
68 section_kinds
["protected-static-attrib"] = defaults
70 defaults
= new MemberDefaults("package", false, false)
71 section_kinds
["package-type"] = defaults
72 section_kinds
["package-func"] = defaults
73 section_kinds
["package-attrib"] = defaults
74 defaults
= new MemberDefaults("package", true, false)
75 section_kinds
["package-static-func"] = defaults
76 section_kinds
["package-static-attrib"] = defaults
78 defaults
= new MemberDefaults("private", false, false)
79 section_kinds
["private-type"] = defaults
80 section_kinds
["private-func"] = defaults
81 section_kinds
["private-attrib"] = defaults
82 section_kinds
["private-slot"] = defaults
83 defaults
= new MemberDefaults("private", true, false)
84 section_kinds
["private-static-func"] = defaults
85 section_kinds
["private-static-attrib"] = defaults
87 defaults
= new MemberDefaults("public", true, true)
88 section_kinds
["related"] = defaults
89 section_kinds
["user-defined"] = defaults
92 redef fun entity
: Entity do return compound
94 redef fun start_dox_element
(local_name
: String, atts
: Attributes) do
95 if ["compoundname", "innerclass", "innernamespace"].has
(local_name
) then
96 text
.listen_until
(dox_uri
, local_name
)
97 if ["innerclass", "innernamespace"].has
(local_name
) then
98 refid
= get_required
(atts
, "refid")
100 else if "basecompoundref" == local_name
then
101 refid
= get_optional
(atts
, "refid", "")
102 prot
= get_optional
(atts
, "prot", "")
103 virt
= get_optional
(atts
, "virt", "")
104 text
.listen_until
(dox_uri
, local_name
)
105 else if "memberdef" == local_name
then
107 else if local_name
== "sectiondef" then
108 member_defaults
= section_kinds
[get_required
(atts
, "kind")]
109 if member_defaults
.is_special
then
112 else if "param" == local_name
then
113 param_listener
.listen_until
(dox_uri
, local_name
)
114 else if "templateparamlist" != local_name
then
119 redef fun end_dox_element
(local_name
: String) do
120 if local_name
== "compoundname" then
121 compound
.full_name
= text
.to_s
122 else if local_name
== "innerclass" then
123 compound
.declare_class
(refid
, text
.to_s
)
124 else if local_name
== "innernamespace" then
125 compound
.declare_namespace
(refid
, text
.to_s
)
126 else if "memberdef" == local_name
then
127 if not (memberdef
.member
isa UnknownMember) then
128 compound
.declare_member
(memberdef
.member
)
130 else if local_name
== "basecompoundref" then
131 compound
.declare_super
(refid
, text
.to_s
, prot
, virt
)
132 else if "param" == local_name
and compound
isa ClassCompound then
133 compound
.as(ClassCompound).add_type_parameter
(param_listener
.parameter
)
139 private fun read_member
(atts
: Attributes) do
140 var kind
= get_required
(atts
, "kind")
143 memberdef
.member
.model_id
= get_required
(atts
, "id")
144 memberdef
.member
.visibility
= get_optional
(atts
, "prot",
145 member_defaults
.visibility
)
148 private fun create_member
(kind
: String) do
149 if kind
== "variable" then
150 memberdef
.member
= new Attribute(compound
.graph
)
151 else if kind
== "function" then
152 memberdef
.member
= new Method(compound
.graph
)
154 memberdef
.member
= new UnknownMember(compound
.graph
)
155 noop
.listen_until
(dox_uri
, "memberdef")
158 memberdef
.listen_until
(dox_uri
, "memberdef")
162 # Default attributes for members in the current section.
163 private class MemberDefaults
164 var visibility
: String