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 # Doxygen’s XML documents reading.
20 # Reader for XML documents whose the schema is `compound.xsd`.
21 class CompoundFileReader
25 var model
: ProjectGraph
27 private var reader
: XMLReader = new XophonReader
28 private var compounddef
: CompoundDefListener is noinit
29 private var noop
: NoopListener is noinit
32 compounddef
= new CompoundDefListener(reader
, self)
33 noop
= new NoopListener(reader
, self)
36 redef fun graph
do return model
38 # Read the document at the specified path.
39 fun read
(path
: String) do
40 reader
.content_handler
= self
41 reader
.parse_file
(path
)
42 compounddef
.compound
= new UnknownCompound(model
)
45 redef fun start_dox_element
(local_name
: String, atts
: Attributes) do
46 if local_name
== "compounddef" then
48 else if "doxygen" != local_name
then
49 noop
.listen_until
(dox_uri
, local_name
)
53 private fun read_compound
(atts
: Attributes) do
54 var kind
= get_required
(atts
, "kind")
57 # TODO Make all values of `kind` and `visibility` compatible with the Nit meta-model.
58 if get_bool
(atts
, "final") then
61 if get_bool
(atts
, "sealed") then
62 kind
= "sealed {kind}"
64 if get_bool
(atts
, "abstract") then
65 kind
= "abstract {kind}"
67 compounddef
.compound
.kind
= kind
68 compounddef
.compound
.model_id
= get_required
(atts
, "id")
69 compounddef
.compound
.visibility
= get_optional
(atts
, "prot", "")
72 private fun create_compound
(kind
: String) do
73 if kind
== "file" then
74 compounddef
.compound
= new FileCompound(model
)
75 else if kind
== "namespace" then
76 compounddef
.compound
= new Namespace(model
)
77 else if kind
== "class" or kind
== "interface" or kind
== "enum" then
78 compounddef
.compound
= new ClassCompound(model
)
80 compounddef
.compound
= new UnknownCompound(model
)
81 noop
.listen_until
(dox_uri
, "compounddef")
84 compounddef
.listen_until
(dox_uri
, "compounddef")