model: add MEntity::mdoc_or_fallback to get more documentation
authorJean Privat <jean@pryen.org>
Mon, 1 Dec 2014 19:47:26 +0000 (14:47 -0500)
committerJean Privat <jean@pryen.org>
Tue, 2 Dec 2014 15:09:51 +0000 (10:09 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/model/mdoc.nit
src/model/mmodule.nit
src/model/mproject.nit

index abc733a..2f8d045 100644 (file)
@@ -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.
index f2c11a6..a92d065 100644 (file)
@@ -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.
index c23e5cb..b89eced 100644 (file)
@@ -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