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 location
=(location
: nullable Location) do
55 class_def
.location
= location
60 class_def
["mdoc"] = doc
63 redef fun declare_super
(id
: String, full_name
: String, prot
: String, virt
: String) do
64 class_def
.declare_super
(id
, full_name
, prot
, virt
)
67 redef fun declare_member
(member
: Member) do
68 class_def
.declare_member
(member
)
71 # Append the specified type parameter.
72 fun add_type_parameter
(parameter
: TypeParameter) do
73 class_type
.arguments
.add
(parameter
)
76 redef fun put_in_graph
do
78 class_type
.put_in_graph
79 class_def
.put_in_graph
82 redef fun put_edges
do
84 graph
.add_edge
(self, "CLASSTYPE", class_type
)
86 var names
= new JsonArray
88 for p
in class_type
.arguments
do
91 self["parameter_names"] = names
96 # The `MClassDef` node of a class.
101 var class_compound
: ClassCompound
103 # The `model_id` of the base classes.
104 var supers
: SimpleCollection[String] = new Array[String]
106 # The set of the introduced/redefined members.
108 # Includes inner classes.
110 # Filled by `declare_member` and `declare_class`.
112 # Note: `declare_class` is defined by the `inner_class` module.
114 # SEE: `declare_member`
115 # SEE: `declare_class`
116 var members
: SimpleCollection[MemberOrInner] = new Array[MemberOrInner]
120 self.labels
.add
("MClassDef")
121 self["is_intro"] = true
124 # Declare a base compound (usually, a base class).
128 # * `id`: `model_id` of the base compound. May be empty.
129 # * `full_name`: qualified name of the base compound. May be empty.
130 # * `prot`: visibility (proctection) of the relationship.
131 # * `virt`: level of virtuality of the relationship.
132 fun declare_super
(id
: String, full_name
: String, prot
: String,
134 # TODO prot, virt, full_name
140 # Append the specified member.
141 fun declare_member
(member
: Member) do
145 redef fun put_edges
do
147 graph
.add_edge
(self, "BOUNDTYPE", class_compound
.class_type
)
148 graph
.add_edge
(self, "MCLASS", class_compound
)
150 graph
.add_edge
(self, "INHERITS", graph
.by_id
[s
].as(ClassCompound).class_type
)
154 var intro
= m
.introducer
.as(not null)
155 graph
.add_edge
(self, "INTRODUCES", intro
)
156 graph
.add_edge
(intro
, "INTRO_CLASSDEF", self)
158 graph
.add_edge
(self, "DECLARES", m
)
163 # A type defined by a class.
167 # The associated class.
169 # You may use this attribute or `class_compound_id` to specify the class.
170 var class_compound
: nullable ClassCompound = null is writable
172 # The `model_id` of the associated class.
174 # You may use this attribute or `class_compound` to specify the class.
175 var class_compound_id
: String = "" is writable
177 # The type arguments or the type parameters.
178 var arguments
= new Array[TypeEntity]
182 self.labels
.add
("MClassType")
185 # Return the number of arguments.
186 fun arity
: Int do return arguments
.length
188 # Is the class generic?
189 fun is_generic
: Bool do return arity
> 0
191 redef fun put_in_graph
do
194 self.labels
.add
("MGenericType")
196 var i
= self.labels
.index_of
("MGenericType")
197 if i
>= 0 then self.labels
.remove_at
(i
)
201 redef fun put_edges
do
202 var cls
= class_compound
204 if cls
== null and class_compound_id
!= "" then
205 cls
= graph
.by_id
[class_compound_id
].as(ClassCompound)
210 graph
.add_edge
(self, "CLASS", cls
)
211 assert cls
.arity
== self.arity
212 for i
in [0..arguments
.length
[ do
214 if cls
.class_type
!= self then
215 a
.name
= cls
.class_type
.arguments
[i
].name
217 if a
isa TypeParameter then
219 graph
.add_edge
(a
, "CLASS", cls
)
221 graph
.add_edge
(self, "ARGUMENT", a
)