From: Jean Privat Date: Mon, 1 Dec 2014 19:47:26 +0000 (-0500) Subject: model: add MEntity::mdoc_or_fallback to get more documentation X-Git-Tag: v0.7~87^2~1 X-Git-Url: http://nitlanguage.org model: add MEntity::mdoc_or_fallback to get more documentation Signed-off-by: Jean Privat --- diff --git a/src/model/mdoc.nit b/src/model/mdoc.nit index abc733a..2f8d045 100644 --- a/src/model/mdoc.nit +++ b/src/model/mdoc.nit @@ -33,6 +33,16 @@ redef class MEntity # The documentation associated to the entity var mdoc: nullable MDoc is writable + # The documentation associated to the entity or their main nested entity. + # + # MProject fall-back to their root MGroup + # MGroup fall-back to their default_mmodule + # 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. diff --git a/src/model/mmodule.nit b/src/model/mmodule.nit index f2c11a6..a92d065 100644 --- a/src/model/mmodule.nit +++ b/src/model/mmodule.nit @@ -63,6 +63,13 @@ redef class MGroup # Return `null` if the group has no default module or if the default # module is not loaded. var default_mmodule: nullable MModule = null + + redef fun mdoc_or_fallback + do + if mdoc != null then return mdoc + if default_mmodule == null then return null + return default_mmodule.mdoc_or_fallback + end end # A Nit module is usually associated with a Nit source file. diff --git a/src/model/mproject.nit b/src/model/mproject.nit index c23e5cb..b89eced 100644 --- a/src/model/mproject.nit +++ b/src/model/mproject.nit @@ -18,6 +18,7 @@ module mproject import model_base private import more_collections import poset +import mdoc # A Nit project, that encompass a product class MProject @@ -45,6 +46,12 @@ class MProject # MProject are always roots of the concerns hierarchy redef fun parent_concern do return null + + redef fun mdoc_or_fallback + do + if mdoc != null then return mdoc + return root.mdoc_or_fallback + end end # A group of modules in a project