This class is useful to generalize presentation of entities to the human.
nitc :: MEntity :: _const_color
nitc :: MEntity :: _css_classes
CSS classes used to decorateself
nitc :: MEntity :: _deprecation
Is the entity deprecated?nitc :: MEntity :: _html_full_name
The MEntityfull_name
escaped for HTML
nitc :: MEntity :: _is_broken
The indication that the entity did not pass some semantic verifications.nitc :: MEntity :: add_doc_to_infobox
Append an entry for the doc in the given infoboxnitc :: 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 :: MEntity :: collect_linearization
Collectself
linearization anchored on mainmodule
nitc :: MEntity :: collect_metrics
nitc :: MEntity :: collect_modifiers
Collect modifier keywords likeredef
, private
etc
nitc :: MEntity :: collect_parents
Collectself
parents (direct ancestors)
nitc :: MEntity :: const_color
nitc :: MEntity :: const_color=
nitc :: MEntity :: core_serialize_base
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 :: MEntity :: defaultinit
nitc :: MEntity :: deprecation=
Is the entity deprecated?nitc :: MEntity :: field_separator
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 :: MEntity :: is_broken=
The indication that the entity did not pass some semantic verifications.nitc :: MEntity :: is_fictive=
Isself
created for internal purpose?
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.mentity
nitc :: MEntity :: ratings_by_dimension
Get the ratings of adimension
nitc :: MEntity :: source_url
Render a HTML link for the MEntity locationnitc :: 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 declarationsnitc :: json_model $ MEntity :: core_serialize_to
Actual serialization ofself
to serializer
nitc :: api_base $ MEntity :: core_serialize_to
Actual serialization ofself
to serializer
nitc :: json_model $ MEntity :: from_deserializer
Create an instance of this class from thedeserializer
nitc :: static_html $ MEntity :: to_dot_node
Returnself
as a DotNode
nitc :: MEntity :: _const_color
nitc :: MEntity :: _css_classes
CSS classes used to decorateself
nitc :: MEntity :: _deprecation
Is the entity deprecated?nitc :: MEntity :: _html_full_name
The MEntityfull_name
escaped for HTML
nitc :: MEntity :: _is_broken
The indication that the entity did not pass some semantic verifications.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 infoboxserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: 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 :: MEntity :: collect_linearization
Collectself
linearization anchored on mainmodule
nitc :: MEntity :: collect_metrics
nitc :: MEntity :: collect_modifiers
Collect modifier keywords likeredef
, private
etc
nitc :: MEntity :: collect_parents
Collectself
parents (direct ancestors)
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 :: MEntity :: defaultinit
core :: Object :: defaultinit
nitc :: HInfoBoxable :: 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 :: 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 :: HInfoBoxable :: infobox
An new infobox documenting the entitynitc :: 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.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
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 :: MEntity :: source_url
Render a HTML link for the MEntity locationserialization :: 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
invariant
and ensure
).
nitc :: MErrorType
A special type used as a silent error marker when building types.nitc :: ModelDiamond
A standalone model with the common class diamond-hierarchy ABCD
# A named and possibly documented entity in the model.
# This class is useful to generalize presentation of entities to the human.
abstract class MEntity
# The short (unqualified) name of this model entity.
#
# The short-name is based from the identifiers used to declare or denote the entity.
# It is usually globally ambiguous but is often enough in a precise local context.
#
# It is suitable to use the short-name in message to the user.
# However, special care must be used in case of potential ambiguities or name conflict.
fun name: String is abstract
# A fully-qualified name of this model entity.
#
# The full-name is based on the short name and is usually prefixed by the name of an outer entity.
# Usually the quad (`::`) is used to separate the different names.
#
# The full-name is expected to be unique and unambiguous in lawful Nit models for the same kind of entity.
#
# It is often suitable to use it in message to the user.
# However, some full-name could be long and verbose,
#
# See the specific implementation in subclasses for details.
fun full_name: String is abstract
# A fully-qualified C-like identifier of this model entity.
#
# The C-name is a name that respects the rule of identifiers in the C language:
# it is only made of alphanumeric characters and starts with a letter (or a underscore).
#
# The C-name can be seen as a mangled version of the `full_name`.
# Therefore, it is expected to be unique and unambiguous in lawful Nit models for the same kind of entity.
#
# The C-name is used by tools that need some identifiers in generated files to designate the
# entity.
#
# Is is not suitable to use it directly with the user (e.g. in message) and
# indirect use should be restricted (e.g. to name a web-page)
fun c_name: String is abstract
# The origin of the definition.
#
# Most model entities are defined in a specific place in the source base.
#
# Because most model entities have one,
# it is simpler for the client to have a non-nullable return value.
# For entities that lack a location, mock-up special locations are used instead.
# By default it is `model.no_location`.
fun location: Location do return model.no_location
# A Model Entity has a direct link to its model
fun model: Model is abstract
# The indication that the entity did not pass some semantic verifications.
#
# This simple flag is set by a given analysis to say that the entity is broken and unusable in
# an execution.
# When an entity status is set to broken, it is usually associated with a error message.
#
# If it is safe to do so, clients of the model SHOULD just skip broken entities in their processing.
# Clients that do not care about the executability (e.g. metrics) MAY still process the entity or
# perform specific checks to determinate the validity of the entity.
#
# Note that the broken status is not propagated to enclosing and enclosed entities.
# e.g. a broken method does not make the whole module broken.
var is_broken = false is writable
# Is `self` created for internal purpose?
#
# Fictive entities are used internally but they should not be
# exposed to the final user.
var is_fictive: Bool = false is writable
# Is `self` created for unit testing purpose?
#
# See `nitunit`.
var is_test: Bool = false is writable
end
src/model/model_base.nit:34,1--111,3
redef class MEntity
# The documentation associated to the entity
var mdoc: nullable MDoc = null is writable
# The documentation associated to the entity or their main nested entity.
#
# * `MPackage`s fall back to their root `MGroup`.
# * `MGroup`s fall back to their `default_mmodule`.
# * `MClass`es, `MClassDef`s, `MProperty`s and `MPropDef`s fall-back to
# their introducing definition.
# * `MClassType`s fall back to their wrapped `MClass`.
# * `MVirtualType`s fall back to their wrapped `MProperty`.
# * `CallSite` fall back on the wrapped `MProperty`.
# * Other entities do not fall back.
#
# One may use `MDoc::original_mentity` to retrieve the original
# source of the documentation.
fun mdoc_or_fallback: nullable MDoc do return mdoc
# Is the entity deprecated?
#
# Used for warnings and in documentation.
# Has no other specific effect.
var deprecation: nullable MDeprecationInfo = null is writable
end
src/model/mdoc.nit:49,1--73,3
redef class MEntity
# The visibility of the MEntity.
#
# MPackages, MGroups and MModules are always public.
# The visibility of `MClass` and `MProperty` is defined by the keyword used.
# `MClassDef` and `MPropDef` return the visibility of `MClass` and `MProperty`.
fun visibility: MVisibility do return public_visibility
end
src/model/model.nit:33,1--40,3
redef class MEntity
# Is `self` existing for an example purpose?
#
# All mentities annotated with `is example` or located inside a mentity that
# is an example are considered as examples.
fun is_example: Bool do return mexample != null
# Return this entity as a MExample
var mexample: nullable MExample = null
# Examples found for `self`
var examples = new Array[MExample]
end
src/model/model_examples.nit:46,1--59,3
redef class MEntity
# Build a `NeoNode` representing `self`.
private fun to_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do
if nodes.has_key(self) then return nodes[self]
var node = make_node(nodes, model_name)
node.labels.add self.class_name
return node
end
# Make a new `NeoNode` based on `mentity`.
private fun make_node(nodes: HashMap[MEntity, NeoNode], model_name: nullable String): NeoNode do
var node = new NeoNode
nodes[self] = node
node.labels.add "MEntity"
if model_name != null then node.labels.add model_name
node["name"] = self.name
if not self isa MSignature then
#FIXME: MSignature is a MEntity, but has no model :/
node["location"] = self.location.to_s
end
var mdoc = self.mdoc
if mdoc != null then
node["mdoc"] = new JsonArray.from(mdoc.content)
node["mdoc_location"] = mdoc.location.to_s
end
return node
end
end
src/neo.nit:987,1--1014,3
redef class MEntity
# Build a ANode from `self`
#
# Allows the creation of an AST node from a model entity.
fun create_ast_representation(astbuilder: nullable ASTBuilder): ANode is abstract
end
src/astbuilder.nit:960,1--965,3
redef class MEntity
# FIXME used to bypass RTA limitation on type resolution
type MENTITY: SELF
# Collect modifier keywords like `redef`, `private` etc
fun collect_modifiers: Array[String] do return new Array[String]
# Collect `self` linearization anchored on `mainmodule`
fun collect_linearization(mainmodule: MModule): nullable Array[MEntity] do
return null
end
# Collect `self` ancestors (direct and indirect)
#
# The concept of ancestor is abstract at this stage.
fun collect_ancestors(mainmodule: MModule, filter: nullable ModelFilter): Set[MENTITY] do
var done = new HashSet[MENTITY]
var todo = new Array[MENTITY]
todo.add_all collect_parents(mainmodule, filter)
while todo.not_empty do
var mentity = todo.pop
if mentity == self or done.has(mentity) then continue
done.add mentity
todo.add_all mentity.collect_parents(mainmodule, filter)
end
return done
end
# Collect `self` parents (direct ancestors)
#
# The concept of parent is abstract at this stage.
fun collect_parents(mainmodule: MModule, filter: nullable ModelFilter): Set[MENTITY] is abstract
# Collect `self` children (direct descendants)
#
# The concept of child is abstract at this stage.
fun collect_children(mainmodule: MModule, filter: nullable ModelFilter): Set[MENTITY] is abstract
# Collect `self` descendants (direct and direct)
#
# The concept of descendant is abstract at this stage.
fun collect_descendants(mainmodule: MModule, filter: nullable ModelFilter): Set[MENTITY] do
var done = new HashSet[MENTITY]
var todo = new Array[MENTITY]
todo.add_all collect_children(mainmodule, filter)
while todo.not_empty do
var mentity = todo.pop
if mentity == self or done.has(mentity) then continue
done.add mentity
todo.add_all mentity.collect_children(mainmodule, filter)
end
return done
end
# Build a poset representing `self` in it's own hierarchy
#
# The notion of hierarchy depends on the type of MEntity.
#
# Here a recap:
# * `MPackage`: package dependencies
# * `MGroup`: group dependencies
# * `MModule`: modules imports
# * `MClass`: class inheritance (all classdefs flattened)
# * `MClassDef`: classdef inheritance
# * `MProperty`: property definitions graph (all propdefs flattened)
# * `MPropDef`: property definitions graph
fun hierarchy_poset(mainmodule: MModule, filter: nullable ModelFilter): POSet[MENTITY] do
var poset = new POSet[MENTITY]
var parents_done = new HashSet[MENTITY]
var parents = new Array[MENTITY]
parents.add self
while parents.not_empty do
var mentity = parents.pop
if parents_done.has(mentity) then continue
parents_done.add mentity
poset.add_node mentity
for parent in mentity.collect_parents(mainmodule, filter) do
poset.add_edge(mentity, parent)
parents.add parent
end
end
var children_done = new HashSet[MEntity]
var children = new Array[MEntity]
children.add self
while children.not_empty do
var mentity = children.pop
if children_done.has(mentity) then continue
children_done.add mentity
for child in mentity.collect_children(mainmodule, filter) do
poset.add_edge(child, mentity)
children.add child
end
end
return poset
end
end
src/model/model_collect.nit:48,1--146,3
redef class MEntity
# Call `v.enter_visit` on all nested entities.
#
# See the specific implementation in the subclasses.
fun visit_all(v: ModelVisitor) do end
end
src/model/model_visitor.nit:99,1--104,3
redef class MEntity
# Text icon to be displayed in front of the entity
fun cs_icon(no_color: nullable Bool): String do
return public_visibility.cs_icon(no_color)
end
# Source code location of this MEntity formatted for console
fun cs_location(no_color: nullable Bool): String do
if no_color == null or not no_color then
return location.to_s.bold.gray
end
return location.to_s
end
# Returns `self.full_name` formatted for console
fun cs_full_name(no_color: nullable Bool): String do
if no_color == null or not no_color then
return full_name.bold.blue
end
return full_name
end
# Returns `self` signature formatted for console.
fun cs_signature(no_color: nullable Bool): String do return ""
# Returns the comment of this MEntity formatted for console.
fun cs_comment(no_color: nullable Bool): nullable String do
var mdoc = mdoc_or_fallback
if mdoc == null then return null
# FIXME add markdown for console
return mdoc.cs_comment(no_color)
end
# Returns the comment of this MEntity formatted for console.
fun cs_short_comment(no_color: nullable Bool): nullable String do
var mdoc = mdoc_or_fallback
if mdoc == null then return null
return mdoc.cs_short_comment(no_color)
end
# Returns the complete MEntity declaration (modifiers + name + signature).
#
# * MPackage: `package foo`
# * MGroup: `group foo`
# * MModule: `module foo`
# * MClass: `private abstract class Foo[E: Object]`
# * MClassDef: `redef class Foo[E]`
# * MProperty: `private fun foo(e: Object): Int`
# * MPropdef: `redef fun foo(e)`
fun cs_declaration(no_color: nullable Bool): String do
var tpl = new FlatBuffer
tpl.append collect_modifiers.join(" ")
tpl.append " "
tpl.append name
tpl.append cs_signature(no_color)
if no_color == null or not no_color then
return tpl.write_to_string.bold
end
return tpl.write_to_string
end
# Returns `self` as a list element that can be displayed in console.
#
# Displays `cs_icon`, `cs_name`, `cs_short_comment, `cs_namespace`,
# `cs_declaration` and `cs_location`.
fun cs_list_item(no_color: nullable Bool): String do
var tpl = new FlatBuffer
tpl.append " "
tpl.append cs_icon(no_color)
tpl.append " "
tpl.append cs_full_name(no_color)
var comment = cs_short_comment(no_color)
if comment != null then
tpl.append "\n "
if no_color == null or not no_color then
tpl.append "# ".green
else
tpl.append "# "
end
tpl.append comment
end
tpl.append "\n "
tpl.append cs_declaration(no_color)
tpl.append "\n "
tpl.append cs_location(no_color)
return tpl.write_to_string
end
# Source code associated to this MEntity.
#
# Uses `cs_location` to locate the source code.
fun cs_source_code: String do
var tpl = new Buffer
tpl.append "\n~~~\n"
tpl.append location.text
tpl.append "\n~~~\n"
return tpl.write_to_string
end
end
src/doc/templates/term_model.nit:47,1--146,3
redef class MEntity
private fun field_separator: String do return "#====#"
private fun line_separator: String do return "#nnnn#"
private fun write_doc(model: Model, mainmodule: MModule, stream: Writer)
do
# 1. Short name for autocompletion
stream.write complete_name
stream.write field_separator
# 2. Full signature
stream.write complete_name
write_signature_to_stream(stream)
stream.write field_separator
# 3. Doc synopsis
var mdoc = complete_mdoc
if mdoc != null then
stream.write mdoc.content.first
end
# 4. Full doc with extra
stream.write field_separator
stream.write "# "
stream.write full_name
write_signature_to_stream(stream)
if mdoc != null then
for i in 2.times do stream.write line_separator
stream.write mdoc.content.join(line_separator)
end
write_location(mainmodule, stream)
write_extra_doc(model, mainmodule, stream)
stream.write "\n"
end
private fun write_signature_to_stream(stream: Writer) do end
# Actual name used in completion
private fun complete_name: String do return name
# Doc to use in completion
private fun complete_mdoc: nullable MDoc do return mdoc
# Extra auto documentation to append to the `stream`
private fun write_extra_doc(model: Model, mainmodule: MModule, stream: Writer) do end
# Location (file and line when available) of related declarations
private fun write_location(mainmodule: MModule, stream: Writer)
do
for i in 2.times do stream.write line_separator
stream.write "## Location"
stream.write line_separator
stream.write "* {location}"
end
end
src/doc/vim_autocomplete.nit:52,1--109,3
redef class MEntity
# Compare MEntity class kind
#
# Unknown kind have a virtually high score.
private fun mentity_kind_rank: Int do return 10
end
src/model/model_index.nit:638,1--644,3
redef class MEntity
super HInfoBoxable
# A HTML version of `to_s` with hyper-links.
#
# By default, `linkto_text(v, to_s)` is used, c.f. see `linkto_text`.
#
# For some complex entities, like generic types, multiple `<a>` and `<span>` elements can be generated.
# E.g. `Array[Int]` might become `<a>Array</a>[<a>Int</a>]` with the correct `href` attributes
# provided by `v.hrefto`.
fun linkto(v: HtmlightVisitor): HTMLTag do return linkto_text(v, to_s)
# Link to the `self` with a specific text.
#
# The whole text is linked with a single `<a>` element.
#
# The `href` used is provided by `v.hrefto`.
# If `href` is null then a `<span>` element is used instead of `<a>`.
fun linkto_text(v: HtmlightVisitor, text: String): HTMLTag
do
var href = v.hrefto(self)
if href == null then
return (new HTMLTag("span")).text(text)
end
return (new HTMLTag("a")).attr("href", href).text(text)
end
# Append an entry for the doc in the given infobox
private fun add_doc_to_infobox(res: HInfoBox)
do
var mdoc = mdoc_or_fallback
if mdoc != null then mdoc.fill_infobox(res)
end
end
src/htmlight.nit:440,1--473,3
redef class MEntity
# Builds a dot UML package diagram entity from `self`
fun tpl_module(model: UMLModel): Writable is abstract
end
src/uml/uml_module.nit:43,1--46,3
redef class MEntity
fun color: String do
if visibility == public_visibility then
return name.green
else if visibility == protected_visibility then
return name.yellow
else
return name.red
end
end
end
src/test_model_index.nit:37,1--47,3
redef class MEntity
# The MEntity unique ID in the HTML output
var html_id: String is lazy do return full_name.to_cmangle
# The MEntity URL in the HTML output
#
# You MUST redefine this method.
# Depending on your implementation, this URL can be a page URL or an anchor.
var html_url: String is lazy do return html_id
# The MEntity name escaped for HTML
var html_name: String is lazy do return name.html_escape
# The MEntity `full_name` escaped for HTML
var html_full_name: String is lazy do return full_name.html_escape
# Link to the MEntity in the HTML output
#
# You should redefine this method depending on the organization or your
# output.
fun html_link(text, title: nullable String): Link do
if text == null then
text = html_name
end
var mdoc = self.mdoc_or_fallback
if title == null and mdoc != null then
title = mdoc.synopsis
end
return new Link(html_url, text, title)
end
# Returns the complete MEntity declaration decorated with HTML
#
# Examples:
# * MPackage: `package foo`
# * MGroup: `group foo`
# * MModule: `module foo`
# * MClass: `private abstract class Foo[E: Object]`
# * MClassDef: `redef class Foo[E]`
# * MProperty: `private fun foo(e: Object): Int`
# * MPropdef: `redef fun foo(e)`
fun html_declaration: Template do
var tpl = new Template
tpl.add "<span class='signature'>"
for modifier in collect_modifiers do
tpl.add "<span class='modifier'>{modifier}</span> "
end
tpl.add "<span class='name'>{html_link.write_to_string}</span>"
tpl.add html_signature(false)
tpl.add "</span>"
return tpl
end
# Returns the MEntity signature decorated with HTML
#
# This function only returns the parenthesis and return types.
# See `html_declaration` for the full declaration including modifiers and name.
fun html_signature(short: nullable Bool): Template do return new Template
# Returns `full_name` decorated with HTML links
fun html_namespace: Template is abstract
# An icon representative of the mentity
fun html_icon: BSIcon do return new BSIcon("tag", ["text-muted"])
# CSS classes used to decorate `self`
#
# Mainly used for icons.
var css_classes: Array[String] = collect_modifiers is lazy
end
src/doc/templates/html_model.nit:26,1--96,3
redef class MEntity
serialize
private fun core_serialize_base(v: Serializer) do
v.serialize_attribute("name", name)
var mdoc = mdoc_or_fallback
if mdoc != null then
v.serialize_attribute("synopsis", mdoc.synopsis)
end
end
redef fun core_serialize_to(v) do
core_serialize_base(v)
v.serialize_attribute("namespace", json_namespace)
v.serialize_attribute("class_name", class_name)
v.serialize_attribute("full_name", full_name)
v.serialize_attribute("visibility", visibility.to_s)
var mdoc = mdoc_or_fallback
if mdoc != null then
v.serialize_attribute("html_synopsis", mdoc.html_synopsis.write_to_string)
end
var modifiers = collect_modifiers
if modifiers.not_empty then
v.serialize_attribute("modifiers", modifiers)
end
end
# Return `self.full_name` as an object that can be serialized to json.
fun json_namespace: JsonNamespace is abstract
# Return a new MEntityRef to `self`.
fun to_json_ref: MEntityRef do return new MEntityRef(self)
end
src/doc/templates/json_model.nit:33,1--67,3
redef class MEntity
# MEntities composing the breadcrumbs of a nitdoc page
fun nitdoc_breadcrumbs: Array[MEntity] is abstract
end
src/doc/static/static_base.nit:244,1--247,3
redef class MEntity
# Render a HTML link for the MEntity location
private fun source_url(url_pattern: nullable String): String do
var location = self.location
var file = location.file
if file == null then return location.to_s
if url_pattern == null then return file.filename.simplify_path
var url = url_pattern
url = url.replace("%f", file.filename.simplify_path)
url = url.replace("%l", location.line_start.to_s)
url = url.replace("%L", location.line_end.to_s)
return url.simplify_path
end
end
src/doc/static/static_structure.nit:424,1--439,3
redef class MEntity
# URL to `self` within the web interface.
fun web_url: String do return "/doc/" / full_name
# URL to `self` within the JSON api.
fun api_url: String do return "/api/entity/" / full_name
redef fun html_url do return web_url
redef fun core_serialize_to(v) do
super
v.serialize_attribute("web_url", web_url)
v.serialize_attribute("api_url", api_url)
end
end
src/doc/api/api_base.nit:168,1--183,3
redef class MEntity
# Get the ratings of a `dimension`
fun ratings_by_dimension(config: NitwebConfig, dimension: String, user: nullable String): JsonObject do
var match = (new MongoMatch).eq("mentity", full_name).eq("dimension", dimension)
var pipeline = new MongoPipeline
pipeline.match(match)
pipeline.group((new MongoGroup("mean_group")).avg("mean", "$rating"))
var res = config.stars.collection.aggregate(pipeline)
var obj = new JsonObject
obj["mean"] = if res.is_empty then 0.0 else res.first["mean"]
obj["ratings"] = new JsonArray.from(config.stars.find_all(match))
if user != null then
match["user"] = user
obj["user"] = config.stars.find(match)
end
return obj
end
# Get the ratings of a `mentity`
fun ratings(config: NitwebConfig, user: nullable String): JsonObject do
var match = new JsonObject
match["mentity"] = full_name
match["ratings"] = new JsonArray.from(config.stars.find_all(match))
match["feature"] = ratings_by_dimension(config, "feature", user)
match["doc"] = ratings_by_dimension(config, "doc", user)
match["examples"] = ratings_by_dimension(config, "examples", user)
match["code"] = ratings_by_dimension(config, "code", user)
return match
end
end
src/doc/api/api_feedback.nit:214,1--246,3
redef class MEntity
private fun collect_metrics(h: APIStructuralMetrics): nullable JsonObject do return null
end
src/doc/api/api_metrics.nit:79,1--81,3