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 # Common SAX listeners for entity definitions.
16 module doxml
::entitydef
20 # Processes the content of an entity definition.
21 abstract class EntityDefListener
22 super StackableListener
24 # The inner `TextListener`.
25 protected var text
: TextListener is noinit
27 # The inner `DocListener`.
28 protected var doc
: DocListener is noinit
30 # The inner `NoopListener`.
31 protected var noop
: NoopListener is noinit
35 text
= new TextListener(reader
, self)
36 doc
= new DocListener(reader
, self)
37 noop
= new NoopListener(reader
, self)
41 protected fun entity
: Entity is abstract
43 redef fun start_dox_element
(local_name
: String, atts
: Attributes) do
44 if ["briefdescription", "detaileddescription", "inbodydescription"].has
(local_name
) then
46 doc
.listen_until
(dox_uri
, local_name
)
47 else if "location" == local_name
then
48 entity
.location
= get_location
(atts
)
50 noop
.listen_until
(dox_uri
, local_name
)
54 redef fun end_listening
do
59 # Parse the attributes of a `location` element.
60 protected fun get_location
(atts
: Attributes): Location do
61 var location
= new Location
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
79 # Processes the content of a `<param>` element.
80 abstract class ParamListener[T
: Parameter]
81 super EntityDefListener
83 # The current parameter.
84 var parameter
: T
is noinit
86 private var type_listener
: TypeListener is noinit
90 type_listener
= new TypeListener(reader
, self)
93 redef fun entity
do return parameter
95 redef fun listen_until
(uri
, local_name
) do
97 parameter
= create_parameter
100 # Create a new parameter.
101 protected fun create_parameter
: T
is abstract
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
)
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
)
124 # Processes the content of a `<param>` element in a `<templateparamlist>` element.
125 class TypeParamListener
126 super ParamListener[TypeParameter]
128 redef fun create_parameter
do return new TypeParameter(graph
)