neo_doxygen: Move the processing of Doxygen’s names in `doxml`.
[nit.git] / contrib / neo_doxygen / src / doxml / doxyname.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 # Adds a methods to convert Doxygen’s names into short names.
16 module doxml::doxyname
17
18 import model
19
20 redef class Compound
21
22 # Separator used by Doxygen to separate name’s components.
23 protected fun doxyname_separator: String do return "::"
24
25 # Set the `name` using the specified name generated by Doxygen.
26 fun doxyname=(doxyname: String) do
27 name = doxyname.to_short_name(doxyname_separator)
28 end
29
30 # Declare an inner class.
31 #
32 # Note: Althought Doxygen indicates that both arguments are optional,
33 # declarations with an empty ID are not supported yet.
34 #
35 # Parameters:
36 #
37 # * `id`: `model_id` of the inner class.
38 # * `doxyname`: qualified name of the inner class, as generated by Doxygen.
39 # * `prot`: visibility (proctection).
40 #
41 # TODO: Handle cases where only the `doxyname` is available.
42 fun doxygen_declare_class(id: String, doxyname: String, prot: String) do
43 declare_class(id, doxyname.to_short_name(doxyname_separator), prot)
44 end
45 end
46
47 redef class Namespace
48 # Set the `name` and the `full_name` using the specified name generated by Doxygen.
49 redef fun doxyname=(doxyname: String) do
50 full_name = doxyname
51 super
52 end
53 end
54
55 redef class FileCompound
56 redef fun doxyname_separator do return "/"
57 end
58
59 redef class Text
60 # Return the substring that come after the last occurrence of `separator`.
61 #
62 # Return the whole string if `sperator` is not present.
63 private fun to_short_name(separator: String): SELFTYPE do
64 var m = search_last(separator)
65
66 if m == null then
67 return self
68 else
69 return substring_from(m.after)
70 end
71 end
72 end