21d8d3c1232bf512ad0a142f71559921117e2126
[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 var compound: Compound is writable, noinit
26 private var memberdef: MemberDefListener is noinit
27
28 # Default attributes for members in the current section.
29 private var member_defaults: MemberDefaults is noinit
30
31 # For each section kind, default attributes for member in that section.
32 private var section_kinds: DefaultMap[String, MemberDefaults] is noinit
33
34
35 # Attributes of the current `<basecompoundref>` element.
36
37 private var refid = ""
38 private var prot = ""
39 private var virt = ""
40
41
42 init do
43 super
44 var defaults = new MemberDefaults("public", false, false)
45
46 memberdef = new MemberDefListener(reader, self)
47
48 member_defaults = defaults
49 section_kinds = new DefaultMap[String, MemberDefaults](defaults)
50
51 section_kinds["public-type"] = defaults
52 section_kinds["public-func"] = defaults
53 section_kinds["public-attrib"] = defaults
54 section_kinds["public-slot"] = defaults
55 defaults = new MemberDefaults("public", true, false)
56 section_kinds["public-static-func"] = defaults
57 section_kinds["public-static-attrib"] = defaults
58
59 defaults = new MemberDefaults("protected", false, false)
60 section_kinds["protected-type"] = defaults
61 section_kinds["protected-func"] = defaults
62 section_kinds["protected-attrib"] = defaults
63 section_kinds["protected-slot"] = defaults
64 defaults = new MemberDefaults("protected", true, false)
65 section_kinds["protected-static-func"] = defaults
66 section_kinds["protected-static-attrib"] = defaults
67
68 defaults = new MemberDefaults("package", false, false)
69 section_kinds["package-type"] = defaults
70 section_kinds["package-func"] = defaults
71 section_kinds["package-attrib"] = defaults
72 defaults = new MemberDefaults("package", true, false)
73 section_kinds["package-static-func"] = defaults
74 section_kinds["package-static-attrib"] = defaults
75
76 defaults = new MemberDefaults("private", false, false)
77 section_kinds["private-type"] = defaults
78 section_kinds["private-func"] = defaults
79 section_kinds["private-attrib"] = defaults
80 section_kinds["private-slot"] = defaults
81 defaults = new MemberDefaults("private", true, false)
82 section_kinds["private-static-func"] = defaults
83 section_kinds["private-static-attrib"] = defaults
84
85 defaults = new MemberDefaults("public", true, true)
86 section_kinds["related"] = defaults
87 section_kinds["user-defined"] = defaults
88 end
89
90 redef fun entity: Entity do return compound
91
92 redef fun start_dox_element(local_name: String, atts: Attributes) do
93 if ["compoundname", "innerclass", "innernamespace"].has(local_name) then
94 text.listen_until(dox_uri, local_name)
95 if ["innerclass", "innernamespace"].has(local_name) then
96 refid = get_required(atts, "refid")
97 end
98 else if "basecompoundref" == local_name then
99 refid = get_optional(atts, "refid", "")
100 prot = get_optional(atts, "prot", "")
101 virt = get_optional(atts, "virt", "")
102 text.listen_until(dox_uri, local_name)
103 else if "memberdef" == local_name then
104 read_member(atts)
105 else if local_name == "sectiondef" then
106 member_defaults = section_kinds[get_required(atts, "kind")]
107 if member_defaults.is_special then
108 super # TODO
109 end
110 else
111 super
112 end
113 end
114
115 redef fun end_dox_element(local_name: String) do
116 if local_name == "compounddef" then
117 compound.put_in_graph
118 else if local_name == "compoundname" then
119 compound.full_name = text.to_s
120 else if local_name == "innerclass" then
121 compound.declare_class(refid, text.to_s)
122 else if local_name == "innernamespace" then
123 compound.declare_namespace(refid, text.to_s)
124 else if "memberdef" == local_name then
125 if not (memberdef.member isa UnknownMember) then
126 compound.declare_member(memberdef.member)
127 end
128 else if local_name == "basecompoundref" then
129 compound.declare_super(refid, text.to_s, prot, virt)
130 else
131 super
132 end
133 end
134
135 private fun read_member(atts: Attributes) do
136 var kind = get_required(atts, "kind")
137
138 create_member(kind)
139 memberdef.member.model_id = get_required(atts, "id")
140 memberdef.member.visibility = get_optional(atts, "prot",
141 member_defaults.visibility)
142 end
143
144 private fun create_member(kind: String) do
145 if kind == "variable" then
146 memberdef.member = new Attribute(compound.graph)
147 else if kind == "function" then
148 memberdef.member = new Method(compound.graph)
149 else
150 memberdef.member = new UnknownMember(compound.graph)
151 noop.listen_until(dox_uri, "memberdef")
152 return
153 end
154 memberdef.listen_until(dox_uri, "memberdef")
155 end
156 end
157
158 # Default attributes for members in the current section.
159 private class MemberDefaults
160 var visibility: String
161 var is_static: Bool
162 var is_special: Bool
163 end