6727cb3d0d65a4be6c9121d598d8d10560d9a94f
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.
16 module model
::class_compound
26 # The corresponding type.
28 # In the case of a generic class, defines bounds for type parameters.
29 var class_type
: ClassType is noinit
32 var class_def
: ClassDef is noinit
36 class_type
= new ClassType(graph
)
37 class_type
.class_compound
= self
38 class_def
= new ClassDef(graph
, self)
39 self.labels
.add
("MClass")
44 # Return the number of type parameters.
45 fun arity
: Int do return class_type
.arity
47 redef fun name
=(name
: String) do
49 class_type
.name
= name
53 redef fun full_name
=(full_name
: String) do
55 class_type
.full_name
= full_name
56 class_def
.full_name
= full_name
59 redef fun parent_name
=(parent_name
: String) do
61 class_type
.parent_name
= parent_name
62 class_def
.parent_name
= parent_name
65 redef fun location
=(location
: nullable Location) do
67 class_def
.location
= location
72 class_def
["mdoc"] = doc
75 redef fun declare_super
(id
: String, full_name
: String, prot
: String, virt
: String) do
76 class_def
.declare_super
(id
, full_name
, prot
, virt
)
79 redef fun declare_member
(member
: Member) do
80 class_def
.declare_member
(member
)
83 # Append the specified type parameter.
84 fun add_type_parameter
(parameter
: TypeParameter) do
85 class_type
.arguments
.add
(parameter
)
88 redef fun put_in_graph
do
90 class_type
.put_in_graph
91 class_def
.put_in_graph
94 redef fun put_edges
do
96 graph
.add_edge
(self, "CLASSTYPE", class_type
)
98 var names
= new JsonArray
100 for p
in class_type
.arguments
do
103 self["parameter_names"] = names
108 # The `MClassDef` node of a class.
113 var class_compound
: ClassCompound
115 # The `model_id` of the base classes.
116 var supers
: SimpleCollection[String] = new Array[String]
118 # The set of the introduced/redefined members.
120 # Includes inner classes.
122 # To ensure that the `full_name` of each member is correctly set,
123 # `declare_member` or `declare_class` should be used to add each member.
125 # Note: `declare_class` is defined by the `inner_class` module.
126 var members
: SimpleCollection[MemberOrInner] = new Array[MemberOrInner]
130 self.labels
.add
("MClassDef")
131 self["is_intro"] = true
134 # Declare a base compound (usually, a base class).
138 # * `id`: `model_id` of the base compound. May be empty.
139 # * `full_name`: qualified name of the base compound. May be empty.
140 # * `prot`: visibility (proctection) of the relationship.
141 # * `virt`: level of virtuality of the relationship.
142 fun declare_super
(id
: String, full_name
: String, prot
: String,
144 # TODO prot, virt, full_name
150 # Append the specified member.
151 fun declare_member
(member
: Member) do
152 var full_name
= self["full_name"]
154 if full_name
!= null then
155 member
.parent_name
= full_name
.to_s
160 redef fun full_name
=(full_name
: String) do
163 m
.parent_name
= full_name
167 redef fun parent_name
=(parent_name
: String) do
170 m
.parent_name
= full_name
174 redef fun put_edges
do
176 graph
.add_edge
(self, "BOUNDTYPE", class_compound
.class_type
)
177 graph
.add_edge
(self, "MCLASS", class_compound
)
179 graph
.add_edge
(self, "INHERITS", graph
.by_id
[s
].as(ClassCompound).class_type
)
183 var intro
= m
.introducer
.as(not null)
184 graph
.add_edge
(self, "INTRODUCES", intro
)
185 graph
.add_edge
(intro
, "INTRO_CLASSDEF", self)
187 graph
.add_edge
(self, "DECLARES", m
)
192 # A type defined by a class.
196 # The associated class.
198 # You may use this attribute or `class_compound_id` to specify the class.
199 var class_compound
: nullable ClassCompound = null is writable
201 # The `model_id` of the associated class.
203 # You may use this attribute or `class_compound` to specify the class.
204 var class_compound_id
: String = "" is writable
206 # The type arguments or the type parameters.
207 var arguments
= new Array[TypeEntity]
211 self.labels
.add
("MClassType")
214 # Return the number of arguments.
215 fun arity
: Int do return arguments
.length
217 # Is the class generic?
218 fun is_generic
: Bool do return arity
> 0
220 redef fun put_in_graph
do
223 self.labels
.add
("MGenericType")
225 var i
= self.labels
.index_of
("MGenericType")
226 if i
>= 0 then self.labels
.remove_at
(i
)
230 redef fun put_edges
do
231 var cls
= class_compound
233 if cls
== null and class_compound_id
!= "" then
234 cls
= graph
.by_id
[class_compound_id
].as(ClassCompound)
239 graph
.add_edge
(self, "CLASS", cls
)
240 assert cls
.arity
== self.arity
241 for i
in [0..arguments
.length
[ do
243 if cls
.class_type
!= self then
244 a
.name
= cls
.class_type
.arguments
[i
].name
246 if a
isa TypeParameter then
248 graph
.add_edge
(a
, "CLASS", cls
)
250 graph
.add_edge
(self, "ARGUMENT", a
)