A MClassDef
is associated with an explicit (or almost) definition of a
class. Unlike MClass
, a MClassDef
is a local definition that belong to
a specific class and a specific module, and contains declarations like super-classes
or properties.
It is the class definitions that are the backbone of most things in the model:
ClassDefs are defined with regard with other classdefs.
Refinement and specialization are combined to produce a big poset called the Model::mclassdef_hierarchy
.
Moreover, the extension and the intention of types is defined by looking at the MClassDefs.
nitc :: MClassDef :: _bound_mtype
The bounded type associated to the mclassdefnitc :: MClassDef :: _default_init
The special default_init constructornitc :: MClassDef :: _ftype_cache
nitc :: MClassDef :: _ftype_computed
nitc :: MClassDef :: _full_name
The module and class name separated by a '$'.nitc :: MClassDef :: _in_hierarchy
The view of the class definition inmclassdef_hierarchy
nitc :: MClassDef :: _intro_colour
Colour for the border of a class when first introducednitc :: MClassDef :: _intro_mproperties
All properties introduced by the classdefnitc :: MClassDef :: _mprop2npropdef
What is theAPropdef
associated to a MProperty
?
nitc :: MClassDef :: _mpropdefs
All property introductions and redefinitions inself
(not inheritance).
nitc :: MClassDef :: _mpropdefs_by_property
All property introductions and redefinitions (not inheritance) inself
by its associated property.
nitc :: MClassDef :: _redef_colour
Colour for the border of a class when refinednitc :: MClassDef :: _restful_methods
Methods with therestful
annotation in this class
nitc :: MClassDef :: _supertypes
All declared super-typesnitc :: MClassDef :: _target_constructor
nitc :: MClassDef :: add_in_hierarchy
Collect the super-types (set by set_supertypes) to build the hierarchynitc :: MClassDef :: before_all
Methods tagged withbefore_all
in this class definition
nitc :: MClassDef :: bound_mtype
The bounded type associated to the mclassdefnitc :: MClassDef :: bound_mtype=
The bounded type associated to the mclassdefnitc :: MClassDef :: build_self_type
Build the virtual typeSELF
only for introduction MClassDef
nitc :: MClassDef :: collect_abstract_methods
Collect intro abstract mmethodDefnitc :: MClassDef :: collect_all_mattributes
Collect all mattributs inehrited,intro and redefnitc :: MClassDef :: collect_all_methods
Collect all mmethod inehrited,intro and redefnitc :: MClassDef :: collect_inherited_mattributes
Collect mattributes inherited by 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_inherited_mmethods
Collect mmethods inherited by 'self' if accepted byfilter
.
nitc :: MClassDef :: collect_inherited_mproperties
Collect all mproperties inehrited by 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_intro_and_redef_mattributes
Collect intro and redef mattributsnitc :: MClassDef :: collect_intro_and_redef_methods
Collect intro and redef mmethodsnitc :: MClassDef :: collect_intro_and_redef_mpropdefs
Collect intro and redef mpropdefsnitc :: MClassDef :: collect_intro_mattributes
Collect mattributes introduced in 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_intro_mmethods
Collect mmethods introduced in 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_intro_mpropdefs
Collect all property definitions that are introduction inself
nitc :: MClassDef :: collect_intro_mproperties
Collect all mproperties introduced in 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_local_mproperties
Collect mproperties introduced and redefined in 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_mattributedefs
Collect all attribute definitions inself
nitc :: MClassDef :: collect_mmethoddefs
Collect all methods definitions inself
nitc :: MClassDef :: collect_mpropdefs
Collect all property definitions inself
nitc :: MClassDef :: collect_mtypedefs
Collect all virtual types definitions inself
nitc :: MClassDef :: collect_not_define_properties
Collect not defined propertiesnitc :: MClassDef :: collect_redef_mattributes
Collect mattributes redefined in 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_redef_mmethods
Collect mmethods redefined in 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_redef_mpropdefs
Collect all property definitions that are redefinition inself
nitc :: MClassDef :: collect_redef_mproperties
Collect all mproperties redefined in 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: default_init
The special default_init constructornitc :: MClassDef :: default_init=
The special default_init constructornitc :: MClassDef :: defaultinit
nitc :: MClassDef :: ftype_cache
nitc :: MClassDef :: ftype_cache=
nitc :: MClassDef :: ftype_computed
nitc :: MClassDef :: ftype_computed=
nitc :: MClassDef :: full_name=
The module and class name separated by a '$'.nitc :: MClassDef :: get_direct_supermtype
Return the direct parent mtype ofself
nitc :: MClassDef :: in_hierarchy
The view of the class definition inmclassdef_hierarchy
nitc :: MClassDef :: in_hierarchy=
The view of the class definition inmclassdef_hierarchy
nitc :: MClassDef :: intro_colour
Colour for the border of a class when first introducednitc :: MClassDef :: intro_colour=
Colour for the border of a class when first introducednitc :: MClassDef :: intro_mproperties
All properties introduced by the classdefnitc :: MClassDef :: intro_mproperties=
All properties introduced by the classdefnitc :: MClassDef :: mprop2npropdef
What is theAPropdef
associated to a MProperty
?
nitc :: MClassDef :: mprop2npropdef=
What is theAPropdef
associated to a MProperty
?
nitc :: MClassDef :: mpropdefs=
All property introductions and redefinitions inself
(not inheritance).
nitc :: MClassDef :: mpropdefs_by_property
All property introductions and redefinitions (not inheritance) inself
by its associated property.
nitc :: MClassDef :: mpropdefs_by_property=
All property introductions and redefinitions (not inheritance) inself
by its associated property.
nitc :: MClassDef :: redef_colour
Colour for the border of a class when refinednitc :: MClassDef :: redef_colour=
Colour for the border of a class when refinednitc :: MClassDef :: restful_methods
Methods with therestful
annotation in this class
nitc :: MClassDef :: restful_methods=
Methods with therestful
annotation in this class
nitc :: MClassDef :: set_supertypes
Register some super-types for the class (ie "super SomeType")nitc :: MClassDef :: supertypes=
All declared super-typesnitc :: MClassDef :: target_constructor
nitc :: MClassDef :: target_constructor=
nitc :: model_collect $ MClassDef :: collect_children
Collectself
children (direct descendants)
nitc :: model_collect $ MClassDef :: collect_linearization
Collectself
linearization anchored on mainmodule
nitc :: model_collect $ MClassDef :: collect_modifiers
Collect modifier keywords likeredef
, private
etc
nitc :: model_collect $ MClassDef :: collect_parents
Collectself
parents (direct ancestors)
nitc :: vim_autocomplete $ MClassDef :: complete_mdoc
Doc to use in completionnitc :: vim_autocomplete $ MClassDef :: complete_name
Actual name used in completionnitc :: json_model $ MClassDef :: core_serialize_to
Actual serialization ofself
to serializer
nitc :: astbuilder $ MClassDef :: create_ast_representation
Build a ANode fromself
nitc :: term_model $ MClassDef :: cs_signature
Returns the MClassDef generic signature with static bounds.nitc :: html_model $ MClassDef :: css_classes
CSS classes used to decorateself
nitc :: html_model $ MClassDef :: html_namespace
Returnsfull_name
decorated with HTML links
nitc :: html_model $ MClassDef :: html_signature
Returns the MEntity signature decorated with HTMLnitc :: json_model $ MClassDef :: json_namespace
Returnself.full_name
as an object that can be serialized to json.
nitc $ MClassDef :: mdoc_or_fallback
The documentation associated to the entity or their main nested entity.nitc :: model_index $ MClassDef :: mentity_kind_rank
Compare MEntity class kindnitc :: uml_module $ MClassDef :: tpl_module
Builds a dot UML package diagram entity fromself
nitc :: model_visitor $ MClassDef :: visit_all
Visit all the classes and class definitions of the module.nitc :: AnnotatedMEntity :: _annotations
Names of the annotations found onself
declaration
nitc :: MClassDef :: _bound_mtype
The bounded type associated to the mclassdefnitc :: MEntity :: _const_color
nitc :: MEntity :: _css_classes
CSS classes used to decorateself
nitc :: MClassDef :: _default_init
The special default_init constructornitc :: MEntity :: _deprecation
Is the entity deprecated?nitc :: MClassDef :: _ftype_cache
nitc :: MClassDef :: _ftype_computed
nitc :: MClassDef :: _full_name
The module and class name separated by a '$'.nitc :: MEntity :: _html_full_name
The MEntityfull_name
escaped for HTML
nitc :: MClassDef :: _in_hierarchy
The view of the class definition inmclassdef_hierarchy
nitc :: MClassDef :: _intro_colour
Colour for the border of a class when first introducednitc :: MClassDef :: _intro_mproperties
All properties introduced by the classdefnitc :: MEntity :: _is_broken
The indication that the entity did not pass some semantic verifications.nitc :: MClassDef :: _mprop2npropdef
What is theAPropdef
associated to a MProperty
?
nitc :: MClassDef :: _mpropdefs
All property introductions and redefinitions inself
(not inheritance).
nitc :: MClassDef :: _mpropdefs_by_property
All property introductions and redefinitions (not inheritance) inself
by its associated property.
nitc :: MClassDef :: _redef_colour
Colour for the border of a class when refinednitc :: MClassDef :: _restful_methods
Methods with therestful
annotation in this class
nitc :: MClassDef :: _supertypes
All declared super-typesnitc :: MClassDef :: _target_constructor
serialization :: Serializable :: accept_inspect_serializer_core
serialization :: Serializable :: accept_json_serializer
Refinable service to customize the serialization of this class to JSONserialization :: Serializable :: accept_msgpack_attribute_counter
Hook to customize the behavior of theAttributeCounter
serialization :: Serializable :: accept_msgpack_serializer
Hook to customize the serialization of this class to MessagePacknitc :: MEntity :: add_doc_to_infobox
Append an entry for the doc in the given infoboxnitc :: MClassDef :: add_in_hierarchy
Collect the super-types (set by set_supertypes) to build the hierarchyserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
nitc :: AnnotatedMEntity :: annotations
Names of the annotations found onself
declaration
nitc :: AnnotatedMEntity :: annotations=
Names of the annotations found onself
declaration
nitc :: MClassDef :: before_all
Methods tagged withbefore_all
in this class definition
nitc :: MClassDef :: bound_mtype
The bounded type associated to the mclassdefnitc :: MClassDef :: bound_mtype=
The bounded type associated to the mclassdefnitc :: MClassDef :: build_self_type
Build the virtual typeSELF
only for introduction MClassDef
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: MClassDef :: collect_abstract_methods
Collect intro abstract mmethodDefnitc :: MClassDef :: collect_all_mattributes
Collect all mattributs inehrited,intro and redefnitc :: MClassDef :: collect_all_methods
Collect all mmethod inehrited,intro and redefnitc :: MEntity :: collect_ancestors
Collectself
ancestors (direct and indirect)
nitc :: MEntity :: collect_children
Collectself
children (direct descendants)
nitc :: MEntity :: collect_descendants
Collectself
descendants (direct and direct)
nitc :: MClassDef :: collect_inherited_mattributes
Collect mattributes inherited by 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_inherited_mmethods
Collect mmethods inherited by 'self' if accepted byfilter
.
nitc :: MClassDef :: collect_inherited_mproperties
Collect all mproperties inehrited by 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_intro_and_redef_mattributes
Collect intro and redef mattributsnitc :: MClassDef :: collect_intro_and_redef_methods
Collect intro and redef mmethodsnitc :: MClassDef :: collect_intro_and_redef_mpropdefs
Collect intro and redef mpropdefsnitc :: MClassDef :: collect_intro_mattributes
Collect mattributes introduced in 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_intro_mmethods
Collect mmethods introduced in 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_intro_mpropdefs
Collect all property definitions that are introduction inself
nitc :: MClassDef :: collect_intro_mproperties
Collect all mproperties introduced in 'self' withvisibility >= min_visibility
.
nitc :: MEntity :: collect_linearization
Collectself
linearization anchored on mainmodule
nitc :: MClassDef :: collect_local_mproperties
Collect mproperties introduced and redefined in 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_mattributedefs
Collect all attribute definitions inself
nitc :: MEntity :: collect_metrics
nitc :: MClassDef :: collect_mmethoddefs
Collect all methods definitions inself
nitc :: MEntity :: collect_modifiers
Collect modifier keywords likeredef
, private
etc
nitc :: MClassDef :: collect_mpropdefs
Collect all property definitions inself
nitc :: MClassDef :: collect_mtypedefs
Collect all virtual types definitions inself
nitc :: MClassDef :: collect_not_define_properties
Collect not defined propertiesnitc :: MEntity :: collect_parents
Collectself
parents (direct ancestors)
nitc :: MClassDef :: collect_redef_mattributes
Collect mattributes redefined in 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_redef_mmethods
Collect mmethods redefined in 'self' withvisibility >= min_visibility
.
nitc :: MClassDef :: collect_redef_mpropdefs
Collect all property definitions that are redefinition inself
nitc :: MClassDef :: collect_redef_mproperties
Collect all mproperties redefined in 'self' withvisibility >= min_visibility
.
nitc :: MEntity :: const_color
nitc :: MEntity :: const_color=
nitc :: MEntity :: core_serialize_base
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
nitc :: MEntity :: create_ast_representation
Build a ANode fromself
nitc :: MEntity :: cs_comment
Returns the comment of this MEntity formatted for console.nitc :: MEntity :: cs_declaration
Returns the complete MEntity declaration (modifiers + name + signature).nitc :: MEntity :: cs_full_name
Returnsself.full_name
formatted for console
nitc :: MEntity :: cs_list_item
Returnsself
as a list element that can be displayed in console.
nitc :: MEntity :: cs_location
Source code location of this MEntity formatted for consolenitc :: MEntity :: cs_short_comment
Returns the comment of this MEntity formatted for console.nitc :: MEntity :: cs_signature
Returnsself
signature formatted for console.
nitc :: MEntity :: cs_source_code
Source code associated to this MEntity.nitc :: MEntity :: css_classes=
CSS classes used to decorateself
nitc :: MClassDef :: default_init
The special default_init constructornitc :: MClassDef :: default_init=
The special default_init constructornitc :: MClassDef :: defaultinit
nitc :: MEntity :: defaultinit
core :: Object :: defaultinit
nitc :: HInfoBoxable :: defaultinit
nitc :: AnnotatedMEntity :: defaultinit
nitc :: MEntity :: deprecation=
Is the entity deprecated?nitc :: MEntity :: field_separator
serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
nitc :: MClassDef :: ftype_cache
nitc :: MClassDef :: ftype_cache=
nitc :: MClassDef :: ftype_computed
nitc :: MClassDef :: ftype_computed=
nitc :: MClassDef :: full_name=
The module and class name separated by a '$'.nitc :: MClassDef :: get_direct_supermtype
Return the direct parent mtype ofself
nitc :: AnnotatedMEntity :: has_annotation
Doesself
contains annotation
in its declaration?
nitc :: MEntity :: hierarchy_poset
Build a poset representingself
in it's own hierarchy
nitc :: MEntity :: html_declaration
Returns the complete MEntity declaration decorated with HTMLnitc :: MEntity :: html_full_name=
The MEntityfull_name
escaped for HTML
nitc :: MEntity :: html_name=
The MEntity name escaped for HTMLnitc :: MEntity :: html_namespace
Returnsfull_name
decorated with HTML links
nitc :: MEntity :: html_signature
Returns the MEntity signature decorated with HTMLnitc :: MClassDef :: in_hierarchy
The view of the class definition inmclassdef_hierarchy
nitc :: MClassDef :: in_hierarchy=
The view of the class definition inmclassdef_hierarchy
nitc :: HInfoBoxable :: infobox
An new infobox documenting the entitynitc :: MClassDef :: intro_colour
Colour for the border of a class when first introducednitc :: MClassDef :: intro_colour=
Colour for the border of a class when first introducednitc :: MClassDef :: intro_mproperties
All properties introduced by the classdefnitc :: MClassDef :: intro_mproperties=
All properties introduced by the classdefnitc :: MEntity :: is_broken=
The indication that the entity did not pass some semantic verifications.nitc :: MEntity :: is_fictive=
Isself
created for internal purpose?
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
nitc :: MEntity :: json_namespace
Returnself.full_name
as an object that can be serialized to json.
nitc :: MEntity :: line_separator
nitc :: MEntity :: linkto_text
Link to theself
with a specific text.
nitc :: MEntity :: mdoc_or_fallback
The documentation associated to the entity or their main nested entity.nitc :: MClassDef :: mprop2npropdef
What is theAPropdef
associated to a MProperty
?
nitc :: MClassDef :: mprop2npropdef=
What is theAPropdef
associated to a MProperty
?
nitc :: MClassDef :: mpropdefs=
All property introductions and redefinitions inself
(not inheritance).
nitc :: MClassDef :: mpropdefs_by_property
All property introductions and redefinitions (not inheritance) inself
by its associated property.
nitc :: MClassDef :: mpropdefs_by_property=
All property introductions and redefinitions (not inheritance) inself
by its associated property.
serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).mentity
nitc :: MEntity :: ratings_by_dimension
Get the ratings of adimension
nitc :: MClassDef :: redef_colour
Colour for the border of a class when refinednitc :: MClassDef :: redef_colour=
Colour for the border of a class when refinednitc :: MClassDef :: restful_methods
Methods with therestful
annotation in this class
nitc :: MClassDef :: restful_methods=
Methods with therestful
annotation in this class
serialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
serialization :: Serializable :: serialize_to_or_delay
Accept references or force direct serialization (usingserialize_to
)
nitc :: MClassDef :: set_supertypes
Register some super-types for the class (ie "super SomeType")nitc :: MEntity :: source_url
Render a HTML link for the MEntity locationnitc :: MClassDef :: supertypes=
All declared super-typesnitc :: MClassDef :: target_constructor
nitc :: MClassDef :: target_constructor=
serialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
nitc :: MEntity :: tpl_module
Builds a dot UML package diagram entity fromself
v.enter_visit
on all nested entities.
nitc :: MEntity :: write_extra_doc
Extra auto documentation to append to thestream
nitc :: MEntity :: write_location
Location (file and line when available) of related declarationsSerializer::serialize
# A definition (an introduction or a refinement) of a class in a module
#
# A `MClassDef` is associated with an explicit (or almost) definition of a
# class. Unlike `MClass`, a `MClassDef` is a local definition that belong to
# a specific class and a specific module, and contains declarations like super-classes
# or properties.
#
# It is the class definitions that are the backbone of most things in the model:
# ClassDefs are defined with regard with other classdefs.
# Refinement and specialization are combined to produce a big poset called the `Model::mclassdef_hierarchy`.
#
# Moreover, the extension and the intention of types is defined by looking at the MClassDefs.
class MClassDef
super MEntity
# The module where the definition is
var mmodule: MModule
# The associated `MClass`
var mclass: MClass is noinit
# The bounded type associated to the mclassdef
#
# For a non-generic class, `bound_mtype` and `mclass.mclass_type`
# are the same type.
#
# Example:
# For the classdef Array[E: Object], the bound_mtype is Array[Object].
# If you want Array[E], then see `mclass.mclass_type`
#
# ENSURE: `bound_mtype.mclass == self.mclass`
var bound_mtype: MClassType
redef var location
redef fun visibility do return mclass.visibility
# Internal name combining the module and the class
# Example: "mymodule$MyClass"
redef var to_s is noinit
init
do
self.mclass = bound_mtype.mclass
mmodule.add_mclassdef(self)
mclass.mclassdefs.add(self)
if mclass.intro_mmodule == mmodule then
assert not isset mclass._intro
mclass.intro = self
end
self.to_s = "{mmodule}${mclass}"
end
# Actually the name of the `mclass`
redef fun name do return mclass.name
# The module and class name separated by a '$'.
#
# The short-name of the class is used for introduction.
# Example: "my_module$MyClass"
#
# The full-name of the class is used for refinement.
# Example: "my_module$intro_module::MyClass"
redef var full_name is lazy do
if is_intro then
# public gives 'p$A'
# private gives 'p::m$A'
return "{mmodule.namespace_for(mclass.visibility)}${mclass.name}"
else if mclass.intro_mmodule.mpackage != mmodule.mpackage then
# public gives 'q::n$p::A'
# private gives 'q::n$p::m::A'
return "{mmodule.full_name}${mclass.full_name}"
else if mclass.visibility > private_visibility then
# public gives 'p::n$A'
return "{mmodule.full_name}${mclass.name}"
else
# private gives 'p::n$::m::A' (redundant p is omitted)
return "{mmodule.full_name}$::{mclass.intro_mmodule.name}::{mclass.name}"
end
end
redef var c_name is lazy do
if is_intro then
return "{mmodule.c_namespace_for(mclass.visibility)}___{mclass.c_name}"
else if mclass.intro_mmodule.mpackage == mmodule.mpackage and mclass.visibility > private_visibility then
return "{mmodule.c_name}___{mclass.name.to_cmangle}"
else
return "{mmodule.c_name}___{mclass.c_name}"
end
end
redef fun model do return mmodule.model
# All declared super-types
# FIXME: quite ugly but not better idea yet
var supertypes = new Array[MClassType]
# Register some super-types for the class (ie "super SomeType")
#
# The hierarchy must not already be set
# REQUIRE: `self.in_hierarchy == null`
fun set_supertypes(supertypes: Array[MClassType])
do
assert unique_invocation: self.in_hierarchy == null
var mmodule = self.mmodule
var model = mmodule.model
var mtype = self.bound_mtype
for supertype in supertypes do
self.supertypes.add(supertype)
# Register in full_type_specialization_hierarchy
model.full_mtype_specialization_hierarchy.add_edge(mtype, supertype)
# Register in intro_type_specialization_hierarchy
if mclass.intro_mmodule == mmodule and supertype.mclass.intro_mmodule == mmodule then
model.intro_mtype_specialization_hierarchy.add_edge(mtype, supertype)
end
end
end
# Collect the super-types (set by set_supertypes) to build the hierarchy
#
# This function can only invoked once by class
# REQUIRE: `self.in_hierarchy == null`
# ENSURE: `self.in_hierarchy != null`
fun add_in_hierarchy
do
assert unique_invocation: self.in_hierarchy == null
var model = mmodule.model
var res = model.mclassdef_hierarchy.add_node(self)
self.in_hierarchy = res
var mtype = self.bound_mtype
# Here we need to connect the mclassdef to its pairs in the mclassdef_hierarchy
# The simpliest way is to attach it to collect_mclassdefs
for mclassdef in mtype.collect_mclassdefs(mmodule) do
res.poset.add_edge(self, mclassdef)
end
end
# The view of the class definition in `mclassdef_hierarchy`
var in_hierarchy: nullable POSetElement[MClassDef] = null
# Is the definition the one that introduced `mclass`?
fun is_intro: Bool do return isset mclass._intro and mclass.intro == self
# All properties introduced by the classdef
var intro_mproperties = new Array[MProperty]
# All property introductions and redefinitions in `self` (not inheritance).
var mpropdefs = new Array[MPropDef]
# The special default_init constructor
var default_init: nullable MMethodDef = null is writable
# All property introductions and redefinitions (not inheritance) in `self` by its associated property.
var mpropdefs_by_property = new HashMap[MProperty, MPropDef]
# Return the direct parent mtype of `self`
# Exemple
# ~~~nitish
# module 1
#
# class A
# class B
# super A
#
# module 2
#
# redef class A
# class C
# super B
#
# mclassdef_C.get_direct_supermtype == [B]
# ~~~~
fun get_direct_supermtype: Collection[MClassType]
do
# Get the potentiel direct parents
var parents = in_hierarchy.direct_greaters
# Stock the potentiel direct parents
var res = supertypes
for parent in parents do
# remove all super parents of the potentiel direct parents
res.remove_all(parent.supertypes)
# if the length of the potentiel direct parent equal 1 break
if res.length == 1 then break
end
return res
end
redef fun mdoc_or_fallback do return mdoc or else mclass.mdoc_or_fallback
end
src/model/model.nit:628,1--820,3
redef class MClassDef
# What is the `APropdef` associated to a `MProperty`?
# Used to check multiple definition of a property.
var mprop2npropdef: Map[MProperty, APropdef] = new HashMap[MProperty, APropdef]
# Build the virtual type `SELF` only for introduction `MClassDef`
fun build_self_type(modelbuilder: ModelBuilder, nclassdef: AClassdef)
do
if not is_intro then return
var name = "SELF"
var mprop = modelbuilder.try_get_mproperty_by_name(nclassdef, self, name)
# If SELF type is declared nowherer?
if mprop == null then return
# SELF is not a virtual type? it is weird but we ignore it
if not mprop isa MVirtualTypeProp then return
# Is this the intro of SELF in the library?
var intro = mprop.intro
var intro_mclassdef = intro.mclassdef
if intro_mclassdef == self then
var nintro = modelbuilder.mpropdef2npropdef[intro]
# SELF must be declared in Object, otherwise this will create conflicts
if intro_mclassdef.mclass.name != "Object" then
modelbuilder.error(nintro, "Error: the virtual type `SELF` must be declared in `Object`.")
end
# SELF must be public
if mprop.visibility != public_visibility then
modelbuilder.error(nintro, "Error: the virtual type `SELF` must be public.")
end
# SELF must not be fixed
if intro.is_fixed then
modelbuilder.error(nintro, "Error: the virtual type `SELF` cannot be fixed.")
end
return
end
# This class introduction inherits a SELF
# We insert an artificial property to update it
var mpropdef = new MVirtualTypeDef(self, mprop, self.location)
mpropdef.bound = mclass.mclass_type
end
end
src/modelize/modelize_property.nit:529,1--577,3
redef class MClassDef
redef fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do
if nodes.has_key(self) then return nodes[self]
var node = super
node.out_edges.add(new NeoEdge(node, "BOUNDTYPE", bound_mtype.to_node(nodes, model_name)))
node.out_edges.add(new NeoEdge(node, "MCLASS", mclass.to_node(nodes, model_name)))
for mproperty in intro_mproperties do
node.out_edges.add(new NeoEdge(node, "INTRODUCES", mproperty.to_node(nodes, model_name)))
end
for mpropdef in mpropdefs do
node.out_edges.add(new NeoEdge(node, "DECLARES", mpropdef.to_node(nodes, model_name)))
end
for sup in supertypes do
node.out_edges.add(new NeoEdge(node, "INHERITS", sup.to_node(nodes, model_name)))
end
return node
end
end
src/neo.nit:749,1--766,3
redef class MClassDef
private var ftype_cache: nullable ForeignType = null
private var ftype_computed = false
# Associated extern type when defined on this classdef
fun ftype: nullable ForeignType
do
return ftype_cache
end
end
src/ffi/extern_classes.nit:53,1--62,3
redef class MClassDef
super AnnotatedMEntity
redef var is_test is lazy do return has_annotation("test")
end
src/frontend/parse_annotations.nit:113,1--117,3
redef class MClassDef
redef fun create_ast_representation(astbuilder: nullable ASTBuilder): AStdClassdef do
if astbuilder == null then astbuilder = new ASTBuilder(mmodule)
var n_propdefs = new Array[APropdef]
for mpropdef in self.mpropdefs do
n_propdefs.add(mpropdef.create_ast_representation(astbuilder))
end
var n_formaldefs = new Array[AFormaldef]
for mparameter in self.mclass.mparameters do n_formaldefs.add(mparameter.create_ast_representation(astbuilder))
return astbuilder.make_class(self, visibility.create_ast_representation(astbuilder), n_formaldefs, null, n_propdefs, null)
end
end
src/astbuilder.nit:971,1--983,3
redef class MClassDef
# Methods tagged with `before` in this class definition
private fun before: Array[MMethodDef] do
var res = new ArraySet[MMethodDef]
for mpropdef in mpropdefs do
if mpropdef isa MMethodDef and mpropdef.is_before then
res.add mpropdef
end
end
var in_hierarchy = self.in_hierarchy
if in_hierarchy == null then return res.to_a
for mclassdef in in_hierarchy.direct_greaters do
res.add_all mclassdef.before
end
var lin = res.to_a
mmodule.linearize_mpropdefs(lin)
return lin
end
# Methods tagged with `before_all` in this class definition
private fun before_all: Array[MMethodDef] do
var res = new ArraySet[MMethodDef]
for mpropdef in mpropdefs do
if mpropdef isa MMethodDef and mpropdef.is_before_all then
res.add mpropdef
end
end
var in_hierarchy = self.in_hierarchy
if in_hierarchy == null then return res.to_a
for mclassdef in in_hierarchy.direct_greaters do
res.add_all mclassdef.before_all
end
var lin = res.to_a
mmodule.linearize_mpropdefs(lin)
return lin
end
# Methods tagged with `after` in this class definition
private fun after: Array[MMethodDef] do
var res = new ArraySet[MMethodDef]
for mpropdef in mpropdefs do
if mpropdef isa MMethodDef and mpropdef.is_after then
res.add mpropdef
end
end
var in_hierarchy = self.in_hierarchy
if in_hierarchy == null then return res.to_a
for mclassdef in in_hierarchy.direct_greaters do
res.add_all mclassdef.after
end
var lin = res.to_a
mmodule.linearize_mpropdefs(lin)
return lin.reversed
end
# Methods tagged with `after_all` in this class definition
private fun after_all: Array[MMethodDef] do
var res = new ArraySet[MMethodDef]
for mpropdef in mpropdefs do
if mpropdef isa MMethodDef and mpropdef.is_after_all then
res.add mpropdef
end
end
var in_hierarchy = self.in_hierarchy
if in_hierarchy == null then return res.to_a
for mclassdef in in_hierarchy.direct_greaters do
res.add_all mclassdef.after_all
end
var lin = res.to_a
mmodule.linearize_mpropdefs(lin)
return lin.reversed
end
end
src/testing/testing_suite.nit:470,1--542,3
redef class MClassDef
redef fun collect_modifiers do
var res = super
if not is_intro then
res.add "redef"
else
if mclass.visibility != public_visibility then
res.add mclass.visibility.to_s
end
end
res.add mclass.kind.to_s
return res
end
redef fun collect_linearization(mainmodule) do
var mclassdefs = new Array[MClassDef]
for mclassdef in in_hierarchy.as(not null).greaters do
if mclassdef.mclass == self.mclass then mclassdefs.add mclassdef
end
mainmodule.linearize_mclassdefs(mclassdefs)
return mclassdefs
end
redef fun collect_parents(mainmodule, filter) do
var res = new HashSet[MENTITY]
var hierarchy = self.in_hierarchy
if hierarchy == null then return res
for parent in hierarchy.direct_greaters do
if parent == self then continue
if filter == null or filter.accept_mentity(parent) then res.add parent
end
return res
end
redef fun collect_children(mainmodule, filter) do
var res = new HashSet[MENTITY]
var hierarchy = self.in_hierarchy
if hierarchy == null then return res
for child in hierarchy.direct_smallers do
if child == self then continue
if filter == null or filter.accept_mentity(child) then res.add child
end
return res
end
# Collect all property definitions in `self`
fun collect_mpropdefs(filter: nullable ModelFilter): Set[MPropDef] do
var res = new HashSet[MPropDef]
for mpropdef in mpropdefs do
if filter == null or filter.accept_mentity(mpropdef) then res.add mpropdef
end
return res
end
# Collect all attribute definitions in `self`
fun collect_mattributedefs(filter: nullable ModelFilter): Set[MAttributeDef] do
var res = new HashSet[MAttributeDef]
for mpropdef in collect_mpropdefs(filter) do
if not mpropdef isa MAttributeDef then continue
res.add mpropdef
end
return res
end
# Collect all methods definitions in `self`
fun collect_mmethoddefs(filter: nullable ModelFilter): Set[MMethodDef] do
var res = new HashSet[MMethodDef]
for mpropdef in collect_mpropdefs(filter) do
if not mpropdef isa MMethodDef then continue
res.add mpropdef
end
return res
end
# Collect all virtual types definitions in `self`
fun collect_mtypedefs(filter: nullable ModelFilter): Set[MVirtualTypeDef] do
var res = new HashSet[MVirtualTypeDef]
for mpropdef in collect_mpropdefs(filter) do
if not mpropdef isa MVirtualTypeDef then continue
res.add mpropdef
end
return res
end
# Collect all property definitions that are introduction in `self`
fun collect_intro_mpropdefs(filter: nullable ModelFilter): Set[MPropDef] do
var res = new HashSet[MPropDef]
for mpropdef in mpropdefs do
if not mpropdef.is_intro then continue
if filter == null or filter.accept_mentity(mpropdef) then res.add mpropdef
end
return res
end
# Collect all property definitions that are redefinition in `self`
fun collect_redef_mpropdefs(filter: nullable ModelFilter): Set[MPropDef] do
var res = new HashSet[MPropDef]
for mpropdef in mpropdefs do
if mpropdef.is_intro then continue
if filter == null or filter.accept_mentity(mpropdef) then res.add mpropdef
end
return res
end
end
src/model/model_collect.nit:968,1--1072,3
redef class MClassDef
# Visit all the classes and class definitions of the module.
#
# On property introduction, the `MProperty` then the `MPropDef` are visited.
# On property redefinition, only the `MPropDef` is visited (the `MProperty` is visited in an inherited class).
# On property inheritance, nothing is visited (the `MProperty` and the `MPropDef` are visited in inherited classes).
redef fun visit_all(v) do
for x in mpropdefs do
if x.is_intro then v.enter_visit(x.mproperty)
v.enter_visit(x)
end
end
end
src/model/model_visitor.nit:142,1--154,3
redef class MClassDef
# Methods with the `restful` annotation in this class
private var restful_methods = new Array[MMethod]
end
src/nitrestful.nit:88,1--92,3
redef class MClassDef
redef fun cs_icon(no_color) do
if is_intro then return visibility.cs_icon(no_color)
return visibility.cs_visibility_color("*")
end
# Returns the MClassDef generic signature with static bounds.
redef fun cs_signature(no_color) do
var tpl = new FlatBuffer
var mparameters = mclass.mparameters
if not mparameters.is_empty then
tpl.append "["
for i in [0..mparameters.length[ do
tpl.append "{mparameters[i].name}: "
tpl.append bound_mtype.arguments[i].cs_signature(no_color)
if i < mparameters.length - 1 then tpl.append ", "
end
tpl.append "]"
end
return tpl.write_to_string
end
end
src/doc/templates/term_model.nit:153,1--174,3
# Use `MClassDef` as anchor for its constructors only
redef class MClassDef
private var target_constructor: nullable MMethodDef = null
redef fun complete_name
do
var target_constructor = target_constructor
assert target_constructor != null
var params
var mparameters = mclass.mparameters
if not mparameters.is_empty then
params = "[{mparameters.join(", ")}]"
else
params = ""
end
if target_constructor.name != "init" and target_constructor.name != "new" then
return name + params + "." + target_constructor.name
end
return name + params
end
redef fun complete_mdoc
do
var target_constructor = target_constructor
assert target_constructor != null
if target_constructor.name != "init" and target_constructor.name != "new" then
return target_constructor.mdoc
end
return mdoc
end
end
src/doc/vim_autocomplete.nit:151,1--186,3
redef class MClassDef
redef fun mentity_kind_rank do return 5
end
src/model/model_index.nit:662,1--664,3
redef class MClassDef
redef fun infobox(v)
do
var res = new HInfoBox(v, "class {mclass.name}")
res.href = v.hrefto(self)
if not v.show_infobox then return res
if is_intro then
res.new_field("class").text(mclass.name)
else
res.new_field("redef class").text(mclass.name)
res.new_field("intro").add mclass.intro.linkto_text(v, "in {mclass.intro_mmodule.to_s}")
end
add_doc_to_infobox(res)
var in_hierarchy = self.in_hierarchy
if in_hierarchy == null then return res
if in_hierarchy.greaters.length > 1 then
var c = res.new_dropdown("hier", "super-classes")
for x in in_hierarchy.greaters do
if x == self then continue
if not x.is_intro then continue
c.open("li").add x.linkto(v)
end
end
if in_hierarchy.smallers.length > 1 then
var c = res.new_dropdown("hier", "sub-classes")
for x in in_hierarchy.smallers do
if x == self then continue
if not x.is_intro then continue
c.open("li").add x.linkto(v)
end
end
if mclass.mclassdefs.length > 1 then
var c = res.new_dropdown("redefs", "refinements")
for x in mclass.mclassdefs do
if x == self then continue
c.open("li").add x.linkto_text(v, "in {x.mmodule}")
end
end
return res
end
end
src/htmlight.nit:496,1--538,3
redef class MClassDef
# Colour for the border of a class when first introduced
#
# Defaults to a shade of green
var intro_colour = "#58B26A"
# Colour for the border of a class when refined
#
# Defaults to a shade of red
var redef_colour = "#B24758"
redef fun tpl_module(model) do
var name = self.name.escape_to_dot
var t = new Template
t.add "{mmodule.name.escape_to_dot}{name} [\n\tlabel = \"\{"
if mclass.kind == abstract_kind then
t.add "abstract\\n{name}"
else if mclass.kind == interface_kind then
t.add "interface\\n{name}"
else
t.add "{name}"
end
if mclass.arity > 0 then
t.add "["
var mparameters = mclass.mparameters
t.add mparameters.first.name
for i in [1 .. mparameters.length[ do
t.add ", "
t.add mparameters[i].name
end
t.add "]"
end
t.add "|"
for i in mpropdefs do
if not i isa MAttributeDef then continue
if not model.filter.accept_mentity(i) then continue
t.add i.tpl_module(model)
t.add "\\l"
end
t.add "|"
for i in mpropdefs do
if not i isa MMethodDef then continue
if not model.filter.accept_mentity(i) then continue
t.add i.tpl_module(model)
t.add "\\l"
end
t.add "\}\""
if is_intro then
t.add "color=\"{intro_colour}\""
else
t.add "color=\"{redef_colour}\""
end
t.add "\n]\n"
var supers = in_hierarchy.direct_greaters
for i in supers do
if i.mmodule != mmodule then continue
t.add "{i.mmodule}{i.name} -> {mmodule}{name} [dir=back"
if i.mclass.kind == interface_kind then
t.add " arrowtail=open style=dashed"
else
t.add " arrowtail=empty"
end
t.add "]\n"
end
return t
end
end
src/uml/uml_module.nit:63,1--130,3
redef class MClassDef
# Collect all mproperties introduced in 'self' with `visibility >= min_visibility`.
fun collect_intro_mproperties(filter: ModelFilter): Set[MProperty] do
var set = new HashSet[MProperty]
for mprop in self.intro_mproperties do
if not filter.accept_mentity(mprop) then continue
set.add(mprop)
end
return set
end
# Collect mmethods introduced in 'self' with `visibility >= min_visibility`.
fun collect_intro_mmethods(filter: ModelFilter): Set[MMethod] do
var res = new HashSet[MMethod]
for mproperty in collect_intro_mproperties(filter) do
if not filter.accept_mentity(mproperty) then continue
if mproperty isa MMethod then res.add(mproperty)
end
return res
end
# Collect mmethods redefined in 'self' with `visibility >= min_visibility`.
fun collect_redef_mmethods(filter: ModelFilter): Set[MMethod] do
var res = new HashSet[MMethod]
for mproperty in collect_redef_mproperties(filter) do
if not filter.accept_mentity(mproperty) then continue
if mproperty isa MMethod then res.add(mproperty)
end
return res
end
# Collect mattributes redefined in 'self' with `visibility >= min_visibility`.
fun collect_redef_mattributes(filter: ModelFilter): Set[MAttribute] do
var res = new HashSet[MAttribute]
for mproperty in collect_redef_mproperties(filter) do
if not filter.accept_mentity(mproperty) then continue
if mproperty isa MAttribute then res.add(mproperty)
end
return res
end
# Collect mattributes introduced in 'self' with `visibility >= min_visibility`.
fun collect_intro_mattributes(filter: ModelFilter): Set[MAttribute] do
var res = new HashSet[MAttribute]
for mproperty in collect_intro_mproperties(filter) do
if not filter.accept_mentity(mproperty) then continue
if mproperty isa MAttribute then res.add(mproperty)
end
return res
end
# Collect all mproperties redefined in 'self' with `visibility >= min_visibility`.
fun collect_redef_mproperties(filter: ModelFilter): Set[MProperty] do
var set = new HashSet[MProperty]
for mpropdef in self.mpropdefs do
if not filter.accept_mentity(mpropdef) then continue
if mpropdef.mproperty.intro_mclassdef.mclass == self then continue
set.add(mpropdef.mproperty)
end
return set
end
# Collect mmethods inherited by 'self' if accepted by `filter`.
fun collect_inherited_mmethods(mainmodule: MModule, filter: ModelFilter): Set[MMethod] do
var res = new HashSet[MMethod]
for mproperty in collect_inherited_mproperties(mainmodule, filter) do
if not filter.accept_mentity(mproperty) then continue
if mproperty isa MMethod then res.add(mproperty)
end
return res
end
# Collect mproperties introduced and redefined in 'self' with `visibility >= min_visibility`.
fun collect_local_mproperties(filter: ModelFilter): Set[MProperty] do
var set = new HashSet[MProperty]
set.add_all collect_intro_mproperties(filter)
set.add_all collect_redef_mproperties(filter)
return set
end
# Collect all mproperties inehrited by 'self' with `visibility >= min_visibility`.
fun collect_inherited_mproperties(mainmodule: MModule, filter: ModelFilter): Set[MProperty] do
var set = new HashSet[MProperty]
for parent in collect_parents(mainmodule, filter) do
set.add_all(parent.collect_intro_mproperties(filter))
set.add_all(parent.collect_inherited_mproperties(mainmodule, filter))
end
return set
end
# Collect mattributes inherited by 'self' with `visibility >= min_visibility`.
fun collect_inherited_mattributes(mainmodule: MModule, filter: ModelFilter): Set[MAttribute] do
var res = new HashSet[MAttribute]
for mproperty in collect_inherited_mproperties(mainmodule, filter) do
if not filter.accept_mentity(mproperty) then continue
if mproperty isa MAttribute then res.add(mproperty)
end
return res
end
# Collect all mmethod inehrited,intro and redef
fun collect_all_methods(mainmodule: MModule, filter: ModelFilter): Set[MMethod] do
var set = new HashSet[MMethod]
set.add_all collect_intro_mmethods(filter)
set.add_all collect_redef_mmethods(filter)
set.add_all collect_inherited_mmethods(mainmodule, filter)
return set
end
# Collect all mattributs inehrited,intro and redef
fun collect_all_mattributes(mainmodule: MModule, filter: ModelFilter): Set[MAttribute] do
var set = new HashSet[MAttribute]
set.add_all collect_redef_mattributes(filter)
set.add_all collect_intro_mattributes(filter)
set.add_all collect_inherited_mattributes(mainmodule, filter)
return set
end
# Collect intro and redef mmethods
fun collect_intro_and_redef_methods(filter: ModelFilter): Set[MMethod] do
var set = new HashSet[MMethod]
set.add_all collect_intro_mmethods(filter)
set.add_all collect_redef_mmethods(filter)
return set
end
# Collect intro and redef mattributs
fun collect_intro_and_redef_mattributes(filter: ModelFilter): Set[MAttribute] do
var set = new HashSet[MAttribute]
set.add_all collect_redef_mattributes(filter)
set.add_all collect_intro_mattributes(filter)
return set
end
# Collect intro and redef mpropdefs
fun collect_intro_and_redef_mpropdefs(filter: ModelFilter): Set[MPropDef] do
var set = new HashSet[MPropDef]
set.add_all collect_intro_mpropdefs(filter)
set.add_all collect_redef_mpropdefs(filter)
return set
end
# Collect intro abstract mmethodDef
fun collect_abstract_methods(filter: ModelFilter): Set[MMethodDef] do
var set = new HashSet[MMethodDef]
var mpropdefs = collect_intro_mpropdefs(filter)
for mpropdef in mpropdefs do
if mpropdef isa MMethodDef then
if mpropdef.is_abstract then set.add(mpropdef)
end
end
return set
end
# Collect not defined properties
fun collect_not_define_properties(filter: ModelFilter):Set[MMethodDef] do
var set = new HashSet[MMethodDef]
for mpropdef in collect_abstract_methods(filter) do
var redef_count = 0
for mprop in mpropdef.mproperty.mpropdefs do
if mprop.is_abstract then continue
redef_count += 1
end
if redef_count == 0 then set.add(mpropdef)
end
return set
end
end
src/metrics/mclassdef_collect.nit:23,1--190,3
redef class MClassDef
redef fun css_classes do return super + mclass.css_classes
redef fun html_namespace do
var tpl = new Template
var mpackage = mmodule.mpackage
if mpackage != null and is_intro then
if is_intro then
tpl.add mpackage.html_namespace
tpl.add " $ "
else
tpl.add mmodule.html_namespace
tpl.add " $ "
var intro_mpackage = mclass.intro.mmodule.mpackage
if intro_mpackage != null and mpackage != intro_mpackage then
tpl.add intro_mpackage.html_namespace
tpl.add " :: "
end
end
else
tpl.add mmodule.html_namespace
tpl.add " $ "
end
tpl.add html_link
return tpl
end
redef fun html_icon do
if is_intro then
return new BSIcon("plus", css_classes)
end
return new BSIcon("asterisk", css_classes)
end
redef fun html_signature(short) do
var tpl = new Template
var mparameters = mclass.mparameters
if not mparameters.is_empty then
tpl.add "["
for i in [0..mparameters.length[ do
tpl.add mparameters[i].html_name
if short == null or not short then
tpl.add ": "
tpl.add bound_mtype.arguments[i].html_signature(short)
end
if i < mparameters.length - 1 then tpl.add ", "
end
tpl.add "]"
end
return tpl
end
end
src/doc/templates/html_model.nit:153,1--204,3
redef class MClassDef
redef fun core_serialize_to(v) do
super
if is_intro then
v.serialize_attribute("is_intro", true)
end
if mclass.mparameters.not_empty then
v.serialize_attribute("mparameters", mclass.mparameters)
end
end
redef fun json_namespace do
var ns = new JsonNamespace
if is_intro then
ns.add_all mmodule.ns_for(mclass.visibility)
ns.add "$"
ns.add mclass.to_json_ref
else if mclass.intro_mmodule.mpackage != mmodule.mpackage then
ns.add_all mmodule.json_namespace
ns.add "$"
ns.add_all mclass.json_namespace
else if mclass.visibility > private_visibility then
ns.add_all mmodule.json_namespace
ns.add "$"
ns.add mclass.to_json_ref
else
ns.add_all mmodule.json_namespace
ns.add "$::"
ns.add mclass.intro_mmodule.to_json_ref
ns.add "::"
ns.add mclass.to_json_ref
end
return ns
end
end
src/doc/templates/json_model.nit:167,1--201,3