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 # Handle language-specific parts of the importation.
16 module doxml
::language_specific
20 # Various importation logics that depend on the project’s language.
21 abstract class SourceLanguage
23 # Apply the information deduced from `type_text` to `member`.
25 # `type_text` is the content of the `<type>` element.
26 fun apply_member_type
(member
: Member, type_text
: RawType) do
27 if type_text
["text"] != null then
28 member
.static_type
= type_text
32 # Apply the information deduced from `type_text` to `parameter`.
34 # `type_text` is the content of the `<type>` element.
35 fun apply_parameter_type
(parameter
: Parameter, type_text
: RawType) do
36 if type_text
["text"] != null then
37 parameter
.static_type
= type_text
41 # Extract the specified keyword at the beginning of the specified text.
43 # If the keyword is at the beginning of the specified text, return `true`
44 # and remove the keyword. Else, return false.
46 # Used to extract some keywords that Doxygen puts in the type.
51 # fun test(text: LinkedText, keyword: String): Bool do
52 # return extract_keyword(text, keyword)
56 # var text = new RawType(new ProjectGraph(""))
57 # var dummy = new DummySource
60 # text.add_part("abstract final", "")
61 # res = dummy.test(text, "static")
63 # res = dummy.test(text, "abstract")
65 # assert "final" == text["text"].as(JsonArray).first
66 # res = dummy.test(text, "final")
68 # assert text["text"] == null
69 # res = dummy.test(text, "abstract")
71 protected fun extract_keyword
(text
: LinkedText, keyword
: String): Bool do
72 var text_array
= text
["text"]
73 if text_array
== null then return false
74 assert text_array
isa JsonArray
75 if text_array
.is_empty
then return false
77 var content
= text_array
.first
.as(String).l_trim
78 var link
= text
.links
.first
81 if link
== null and content
.has_prefix
(keyword
) then
82 if keyword
.length
== content
.length
then
85 else if content
.chars
[keyword
.length
] <= ' ' then
86 content
= content
.substring_from
(keyword
.length
).l_trim
92 text
.set_part
(0, content
, "")
98 # Extract the specified suffix in the specified text.
100 # If the suffix is at the end of the specified text, return `true`
101 # and remove the suffix. Else, return false.
103 # Used to extract stuff like `...` that Doxygen puts in the type.
108 # fun test(text: LinkedText, s: String): Bool do
109 # return extract_suffix(text, s)
113 # var text = new RawType(new ProjectGraph(""))
114 # var dummy = new DummySource
117 # text.add_part("Object...+++", "")
118 # res = dummy.test(text, "...")
120 # res = dummy.test(text, "+++")
122 # assert "Object..." == text["text"].as(JsonArray).first
123 # res = dummy.test(text, "...")
125 # assert "Object" == text["text"].as(JsonArray).first
126 protected fun extract_suffix
(text
: LinkedText, suffix
: String): Bool do
127 var text_array
= text
["text"]
128 if text_array
== null then return false
129 assert text_array
isa JsonArray
130 if text_array
.is_empty
then return false
132 var content
= text_array
.last
.as(String).r_trim
133 var link
= text
.links
.first
135 if link
== null and content
.has_suffix
(suffix
) then
136 content
= content
.substring
(0, content
.length
- suffix
.length
).r_trim
137 if "" == content
then
140 text
.set_part
(0, content
, "")
149 # The default importation logics.
151 # Do nothing special.
156 # Importation logics for Java.
160 redef fun apply_member_type
(member
, type_text
) do
161 # For abstract members, Doxygen put `abstract` at the beginning of the type.
162 # We assume that Doxygen do not put annotations in the type (it seems to
164 if extract_keyword
(type_text
, "abstract") then
165 member
.is_abstract
= true
169 # TODO Avoid using `RawType` when possible. Only use `RawType` as a fallback.
173 redef fun apply_parameter_type
(parmeter
, type_text
) do
174 # We assume that Doxygen do not put annotations in the type (it seems to
177 # TODO Avoid using `RawType` when possible. Only use `RawType` as a fallback.
178 parmeter
.is_vararg
= extract_suffix
(type_text
, "...")