Centralize its definition and update its documentation.
Pull-Request: #2231
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
end
redef class MClass
- redef fun mdoc_or_fallback do return intro.mdoc
redef fun cs_icon do return intro.cs_icon
# Format: `Foo[E]`
end
redef class MClassDef
- redef fun mdoc_or_fallback do return mdoc or else mclass.mdoc_or_fallback
redef fun cs_icon do return "C"
# Depends if `self` is an intro or not.
end
redef class MProperty
- redef fun mdoc_or_fallback do return intro.mdoc
redef fun cs_modifiers do return intro.cs_modifiers
redef fun cs_declaration do return intro.cs_declaration
redef fun cs_icon do return intro.cs_icon
end
redef class MPropDef
- redef fun mdoc_or_fallback do return mdoc or else mproperty.mdoc_or_fallback
-
# Depends if `self` is an intro or not.
#
# * If intro contains the visibility and kind.
end
redef class MClass
- redef fun mdoc_or_fallback do return intro.mdoc
-
# Format: `Foo[E]`
redef var html_name is lazy do
var tpl = new Template
end
redef class MClassDef
- redef fun mdoc_or_fallback do return mdoc or else mclass.mdoc_or_fallback
-
# Depends if `self` is an intro or not.
#
# * If intro contains the visibility and kind.
end
redef class MProperty
- redef fun mdoc_or_fallback do return intro.mdoc
redef fun html_modifiers do return intro.html_modifiers
redef fun html_declaration do return intro.html_declaration
end
redef class MPropDef
- redef fun mdoc_or_fallback do return mdoc or else mproperty.mdoc_or_fallback
-
# Depends if `self` is an intro or not.
#
# * If intro contains the visibility and kind.
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
redef class MModule
var res = new HInfoBox(v, "module {name}")
res.href = v.hrefto(self)
res.new_field("module").add(linkto(v))
- var mdoc = self.mdoc
- if mdoc != null then mdoc.fill_infobox(res)
+ add_doc_to_infobox(res)
if in_importation.greaters.length > 1 then
var c = res.new_dropdown("imports", "{in_importation.greaters.length-1} modules")
for x in in_importation.greaters do
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
- var mdoc = self.mdoc
- if mdoc == null then mdoc = mclass.intro.mdoc
- if mdoc != null then mdoc.fill_infobox(res)
+ add_doc_to_infobox(res)
var in_hierarchy = self.in_hierarchy
if in_hierarchy == null then return res
else
res.new_field("intro").add mproperty.intro.linkto_text(v, "in {mproperty.intro.mclassdef}")
end
- var mdoc = self.mdoc
- if mdoc == null then mdoc = mproperty.intro.mdoc
- if mdoc != null then mdoc.fill_infobox(res)
+ add_doc_to_infobox(res)
if mproperty.mpropdefs.length > 1 then
var c = res.new_dropdown("redef", "redefinitions")
for x in mproperty.mpropdefs do
var res = new HInfoBox(v, to_s)
res.href = v.hrefto(self)
res.new_field("class").add mclass.intro.linkto(v)
- var mdoc = mclass.mdoc
- if mdoc == null then mdoc = mclass.intro.mdoc
- if mdoc != null then mdoc.fill_infobox(res)
+ add_doc_to_infobox(res)
return res
end
redef fun linkto(v)
var res = new HInfoBox(v, to_s)
res.href = v.hrefto(mproperty)
var p = mproperty
- var pd = p.intro
- res.new_field("virtual type").add pd.linkto(v)
- var mdoc = pd.mdoc
+ add_doc_to_infobox(res)
if mdoc != null then mdoc.fill_infobox(res)
return res
end
else
res.new_field("intro").add mproperty.intro.linkto_text(v, "in {mproperty.intro.mclassdef}")
end
- var mdoc = mpropdef.mdoc
- if mdoc == null then mdoc = mproperty.intro.mdoc
- if mdoc != null then mdoc.fill_infobox(res)
+ add_doc_to_infobox(res)
return res
end
# The documentation associated to the entity or their main nested entity.
#
- # MPackage fall-back to their root MGroup
- # MGroup fall-back to their default_mmodule
- # Other entities do not fall-back
+ # * `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`.
+ # * Other entities do not fall back.
#
# One may use `MDoc::original_mentity` to retrieve the original
# source of the documentation.
# Is `self` and abstract class?
var is_abstract: Bool is lazy do return kind == abstract_kind
- redef fun mdoc_or_fallback do return intro.mdoc_or_fallback
+ redef fun mdoc_or_fallback
+ do
+ # Don’t use `intro.mdoc_or_fallback` because it would create an infinite
+ # recursion.
+ return intro.mdoc
+ end
end
# All property introductions and redefinitions (not inheritance) in `self` by its associated property.
var mpropdefs_by_property = new HashMap[MProperty, MPropDef]
+
+ redef fun mdoc_or_fallback do return mdoc or else mclass.mdoc_or_fallback
end
# A global static type
private var collect_mclasses_cache = new HashMap[MModule, Set[MClass]]
private var collect_mtypes_cache = new HashMap[MModule, Set[MClassType]]
+ redef fun mdoc_or_fallback do return mclass.mdoc_or_fallback
end
# A type based on a generic class.
redef fun full_name do return self.mproperty.full_name
redef fun c_name do return self.mproperty.c_name
+
+ redef fun mdoc_or_fallback do return mproperty.mdoc_or_fallback
end
# The type associated to a formal parameter generic type of a class
redef var location
- redef fun mdoc_or_fallback do return intro.mdoc_or_fallback
+ redef fun mdoc_or_fallback
+ do
+ # Don’t use `intro.mdoc_or_fallback` because it would create an infinite
+ # recursion.
+ return intro.mdoc
+ end
# The canonical name of the property.
#
assert has_next_property: i.is_ok
return i.item
end
+
+ redef fun mdoc_or_fallback do return mdoc or else mproperty.mdoc_or_fallback
end
# A local definition of a method