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 # The language-specific strategies to use.
28 redef var source_language
: SourceLanguage
30 private var reader
: XMLReader = new XophonReader
31 private var compounddef
: CompoundDefListener is noinit
32 private var noop
: NoopListener is noinit
35 compounddef
= new CompoundDefListener(reader
, self)
36 noop
= new NoopListener(reader
, self)
39 redef fun graph
do return model
41 # Read the document at the specified path.
42 fun read
(path
: String) do
43 reader
.content_handler
= self
44 reader
.parse_file
(path
)
45 compounddef
.compound
= new UnknownCompound(model
)
48 redef fun start_dox_element
(local_name
: String, atts
: Attributes) do
49 if local_name
== "compounddef" then
51 else if "doxygen" != local_name
then
52 noop
.listen_until
(dox_uri
, local_name
)
56 private fun read_compound
(atts
: Attributes) do
57 var kind
= get_required
(atts
, "kind")
60 # TODO Make all values of `kind` and `visibility` compatible with the Nit meta-model.
61 if get_bool
(atts
, "final") then
64 if get_bool
(atts
, "sealed") then
65 kind
= "sealed {kind}"
67 if get_bool
(atts
, "abstract") then
68 kind
= "abstract {kind}"
70 compounddef
.compound
.kind
= kind
71 compounddef
.compound
.model_id
= get_required
(atts
, "id")
72 compounddef
.compound
.visibility
= get_optional
(atts
, "prot", "")
75 private fun create_compound
(kind
: String) do
76 if kind
== "file" then
77 compounddef
.compound
= new FileCompound(model
)
78 else if kind
== "namespace" then
79 compounddef
.compound
= new Namespace(model
)
80 else if kind
== "class" or kind
== "interface" or kind
== "enum" then
81 compounddef
.compound
= new ClassCompound(model
)
83 compounddef
.compound
= new UnknownCompound(model
)
84 noop
.listen_until
(dox_uri
, "compounddef")
87 compounddef
.listen_until
(dox_uri
, "compounddef")