module model::class_compound
import graph
+import member
import type_entity
# A class.
# Return the number of type parameters.
fun arity: Int do return class_type.arity
- redef fun name=(name: String) do
+ redef fun name=(name) do
super
class_type.name = name
class_def.name = name
end
- redef fun full_name=(full_name: String) do
+ redef fun location=(location) do
super
- class_type.full_name = full_name
- class_def.full_name = full_name
+ class_def.location = location
end
- redef fun parent_name=(parent_name: String) do
+ redef fun set_mdoc do
super
- class_type.parent_name = parent_name
- class_def.parent_name = parent_name
+ class_def["mdoc"] = doc
end
- redef fun location=(location: nullable Location) do
- super
- class_def.location = location
+ redef fun declare_super(id, full_name, prot, virt) do
+ class_def.declare_super(id, full_name, prot, virt)
end
- redef fun set_mdoc do
- super
- class_def["mdoc"] = doc
+ redef fun declare_member(member) do
+ class_def.declare_member(member)
end
- redef fun declare_super(id: String, name: String, prot: String, virt: String) do
- class_def.declare_super(id, name, prot, virt)
+ # Append the specified type parameter.
+ fun add_type_parameter(parameter: TypeParameter) do
+ class_type.arguments.add(parameter)
end
redef fun put_in_graph do
class ClassDef
super CodeBlock
+ # The defined class.
var class_compound: ClassCompound
+
+ # The `model_id` of the base classes.
var supers: SimpleCollection[String] = new Array[String]
+ # The set of the introduced/redefined members.
+ #
+ # Includes inner classes.
+ #
+ # Filled by `declare_member` and `declare_class`.
+ #
+ # Note: `declare_class` is defined by the `inner_class` module.
+ #
+ # SEE: `declare_member`
+ # SEE: `declare_class`
+ var members: SimpleCollection[MemberOrInner] = new Array[MemberOrInner]
+
init do
super
self.labels.add("MClassDef")
+ self["is_intro"] = true
end
- fun declare_super(id: String, name: String, prot: String, virt: String) do
- # TODO prot, virt, name
+ # Declare a base compound (usually, a base class).
+ #
+ # Parameters:
+ #
+ # * `id`: `model_id` of the base compound. May be empty.
+ # * `full_name`: qualified name of the base compound. May be empty.
+ # * `prot`: visibility (proctection) of the relationship.
+ # * `virt`: level of virtuality of the relationship.
+ fun declare_super(id: String, full_name: String, prot: String,
+ virt: String) do
+ # TODO prot, virt, full_name
if "" != id then
supers.add(id)
end
end
+ # Append the specified member.
+ fun declare_member(member: Member) do
+ members.add(member)
+ end
+
redef fun put_edges do
super
graph.add_edge(self, "BOUNDTYPE", class_compound.class_type)
for s in supers do
graph.add_edge(self, "INHERITS", graph.by_id[s].as(ClassCompound).class_type)
end
+ for m in members do
+ if m.is_intro then
+ var intro = m.introducer.as(not null)
+ graph.add_edge(self, "INTRODUCES", intro)
+ graph.add_edge(intro, "INTRO_CLASSDEF", self)
+ end
+ graph.add_edge(self, "DECLARES", m)
+ end
end
end
# You may use this attribute or `class_compound` to specify the class.
var class_compound_id: String = "" is writable
+ # The type arguments or the type parameters.
var arguments = new Array[TypeEntity]
init do
end
# Return the number of arguments.
- fun arity: Int do return 0 # TODO
+ fun arity: Int do return arguments.length
+ # Is the class generic?
fun is_generic: Bool do return arity > 0
redef fun put_in_graph do