6c11a6c9440d47d4edf8d8349fcb82ed75941408
[nit.git] / contrib / neo_doxygen / src / doxml / entitydef.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 # Common SAX listeners for entity definitions.
16 module doxml::entitydef
17
18 import doc
19
20 # Processes the content of an entity definition.
21 abstract class EntityDefListener
22 super StackableListener
23
24 # The inner `TextListener`.
25 protected var text: TextListener is noinit
26
27 # The inner `DocListener`.
28 protected var doc: DocListener is noinit
29
30 # The inner `NoopListener`.
31 protected var noop: NoopListener is noinit
32
33 init do
34 super
35 text = new TextListener(reader, self)
36 doc = new DocListener(reader, self)
37 noop = new NoopListener(reader, self)
38 end
39
40 # The current entity.
41 protected fun entity: Entity is abstract
42
43 redef fun start_dox_element(local_name: String, atts: Attributes) do
44 if ["briefdescription", "detaileddescription", "inbodydescription"].has(local_name) then
45 doc.doc = entity.doc
46 doc.listen_until(dox_uri, local_name)
47 else if "location" == local_name then
48 entity.location = get_location(atts)
49 else
50 noop.listen_until(dox_uri, local_name)
51 end
52 end
53
54 redef fun end_listening do
55 super
56 entity.put_in_graph
57 end
58
59 # Parse the attributes of a `location` element.
60 protected fun get_location(atts: Attributes): Location do
61 var location = new Location
62
63 location.path = atts.value_ns("", "bodyfile") or else atts.value_ns("", "file")
64 # Doxygen may indicate `[generated]`.
65 if "[generated]" == location.path then location.path = null
66 var line_start = atts.value_ns("", "bodystart") or else atts.value_ns("", "line") or else null
67 if line_start != null then location.line_start = line_start.to_i
68 var line_end = atts.value_ns("", "bodyend")
69 if line_end != null then location.line_end = line_end.to_i
70 var column_start = atts.value_ns("", "column")
71 if column_start != null then location.column_start = column_start.to_i
72 if location.line_start == location.line_end then
73 location.column_end = location.column_start
74 end
75 return location
76 end
77 end
78
79 # Processes the content of a `<param>` element.
80 abstract class ParamListener[T: Parameter]
81 super EntityDefListener
82
83 # The current parameter.
84 var parameter: T is noinit
85
86 private var type_listener: TypeListener is noinit
87
88 init do
89 super
90 type_listener = new TypeListener(reader, self)
91 end
92
93 redef fun entity do return parameter
94
95 redef fun listen_until(uri, local_name) do
96 super
97 parameter = create_parameter
98 end
99
100 # Create a new parameter.
101 protected fun create_parameter: T is abstract
102
103 redef fun start_dox_element(local_name: String, atts: Attributes) do
104 if "declname" == local_name then
105 text.listen_until(dox_uri, local_name)
106 else if "type" == local_name then
107 type_listener.listen_until(dox_uri, local_name)
108 else
109 super
110 end
111 end
112
113 redef fun end_dox_element(local_name: String) do
114 if "declname" == local_name then
115 parameter.name = text.to_s
116 else if "type" == local_name then
117 source_language.apply_parameter_type(parameter, type_listener.linked_text)
118 else
119 super
120 end
121 end
122 end
123
124 # Processes the content of a `<param>` element in a `<templateparamlist>` element.
125 class TypeParamListener
126 super ParamListener[TypeParameter]
127
128 redef fun create_parameter do return new TypeParameter(graph)
129 end