ci: do not error when nothing with nitunit_some
[nit.git] / contrib / neo_doxygen / src / doxml / doxml.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 # Doxygen’s XML documents reading.
16 module doxml
17
18 import compounddef
19
20 # Reader for XML documents whose the schema is `compound.xsd`.
21 class CompoundFileReader
22 super DoxmlListener
23
24 # The project graph.
25 var model: ProjectGraph
26
27 # The language-specific strategies to use.
28 redef var source_language: SourceLanguage
29
30 private var reader: XMLReader = new XophonReader
31 private var compounddef: CompoundDefListener is noinit
32 private var noop: NoopListener is noinit
33
34 init do
35 compounddef = new CompoundDefListener(reader, self)
36 noop = new NoopListener(reader, self)
37 end
38
39 redef fun graph do return model
40
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)
46 end
47
48 redef fun start_dox_element(local_name: String, atts: Attributes) do
49 if local_name == "compounddef" then
50 read_compound(atts)
51 else if "doxygen" != local_name then
52 noop.listen_until(dox_uri, local_name)
53 end
54 end
55
56 private fun read_compound(atts: Attributes) do
57 var kind = get_required(atts, "kind")
58
59 create_compound(kind)
60 # TODO Make all values of `kind` and `visibility` compatible with the Nit meta-model.
61 if get_bool(atts, "final") then
62 kind = "final {kind}"
63 end
64 if get_bool(atts, "sealed") then
65 kind = "sealed {kind}"
66 end
67 if get_bool(atts, "abstract") then
68 kind = "abstract {kind}"
69 end
70 compounddef.compound.kind = kind
71 compounddef.compound.model_id = get_required(atts, "id")
72 compounddef.compound.visibility = get_optional(atts, "prot", "")
73 end
74
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)
82 else
83 compounddef.compound = new UnknownCompound(model)
84 noop.listen_until(dox_uri, "compounddef")
85 return
86 end
87 compounddef.listen_until(dox_uri, "compounddef")
88 end
89 end