ci: do not error when nothing with nitunit_some
[nit.git] / contrib / neo_doxygen / src / model / type_entity.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 # Typing and parameters.
16 module model::type_entity
17
18 import graph
19 import linked_text
20
21 # Base class of all types and signatures.
22 abstract class TypeEntity
23 super Entity
24
25 init do
26 super
27 self.labels.add("MType")
28 end
29 end
30
31 # A type parameter or a type argument.
32 #
33 # Note : The class relationship and the rank are set by `MClassType.put_edges`.
34 class TypeParameter
35 super TypeEntity
36 super Parameter
37
38 init do
39 super
40 self.labels.add("MParameterType")
41 end
42 end
43
44
45 # A type described by a text.
46 class RawType
47 super TypeEntity
48 super LinkedText
49
50 init do
51 super
52 self.labels.add("MRawType")
53 end
54
55 redef fun create_link(rank, refid) do return new TypeLink(graph, refid)
56 end
57
58 # A link in a `RawType`.
59 class TypeLink
60 super Link
61
62 init do
63 super
64 self.labels.add("MTypePart")
65 end
66 end
67
68
69 # A signature of a method.
70 class Signature
71 super TypeEntity
72
73 # The parameters.
74 var parameters = new Array[MemberParameter]
75
76 # The static type of the returned value.
77 var return_type: nullable TypeEntity = null is writable
78
79 init do
80 super
81 self.labels.add("MSignature")
82 end
83
84 redef fun put_in_graph do
85 super
86 if return_type isa TypeEntity then
87 return_type.as(TypeEntity).put_in_graph
88 end
89 for p in parameters do
90 p.put_in_graph
91 end
92 end
93
94 redef fun put_edges do
95 super
96 if parameters.length > 0 then
97 var names = new JsonArray
98
99 for i in [0..parameters.length[ do
100 var p = parameters[i]
101 p.rank = i
102 names.add(p.name)
103 graph.add_edge(self, "PARAMETER", p)
104 end
105 self["parameter_names"] = names
106 end
107 if return_type != null then
108 graph.add_edge(self, "RETURNTYPE", return_type.as(not null))
109 end
110 end
111 end
112
113 # A parameter or an argument.
114 abstract class Parameter
115 super Entity
116
117 # The static type of the parameter.
118 var static_type: nullable TypeEntity = null is writable
119
120 init do
121 super
122 self["is_vararg"] = false
123 self["rank"] = -1
124 end
125
126 # Is the parameter a “vararg”?
127 fun is_vararg=(is_vararg: Bool) do
128 self["is_vararg"] = is_vararg
129 end
130
131 # Is the parameter a “vararg”?
132 fun is_vararg: Bool do
133 var value = self["is_vararg"]
134 assert value isa Bool
135 return value
136 end
137
138 # Set the rank (index) of the parameter in the signature.
139 fun rank=(rank: Int) do
140 self["rank"] = rank
141 end
142
143 redef fun put_in_graph do
144 super
145 if static_type != null then
146 static_type.as(not null).put_in_graph
147 end
148 end
149
150 redef fun put_edges do
151 super
152 graph.add_edge(self, "TYPE", static_type.as(not null))
153 end
154 end
155
156 # A parameter of a member.
157 #
158 # Note : The rank are set by `Signature.put_edges`.
159 class MemberParameter
160 super Parameter
161
162 init do
163 super
164 self.labels.add("MParameter")
165 end
166 end