model: add optional MDoc::original_mentity
authorJean Privat <jean@pryen.org>
Tue, 3 Jun 2014 12:44:46 +0000 (08:44 -0400)
committerJean Privat <jean@pryen.org>
Tue, 3 Jun 2014 12:44:46 +0000 (08:44 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/model/mdoc.nit
src/modelbuilder.nit
src/modelize_class.nit
src/modelize_property.nit

index 919b48c..44ddfea 100644 (file)
@@ -23,6 +23,10 @@ class MDoc
        # The starting `#` and first space are stripped.
        # The trailing `\n` are chomped.
        var content = new Array[String]
+
+       # The entity where the documentation is originally attached to.
+       # This gives some context to resolve identifiers or to run examples.
+       var original_mentity: nullable MEntity writable = null
 end
 
 redef class MEntity
index dc48ee9..89e4675 100644 (file)
@@ -616,7 +616,11 @@ class ModelBuilder
 
                if decl != null then
                        var ndoc = decl.n_doc
-                       if ndoc != null then mmodule.mdoc = ndoc.to_mdoc
+                       if ndoc != null then
+                               var mdoc = ndoc.to_mdoc
+                               mmodule.mdoc = mdoc
+                               mdoc.original_mentity = mmodule
+                       end
                end
 
                return mmodule
index a72bfec..f105f5d 100644 (file)
@@ -163,7 +163,11 @@ redef class ModelBuilder
 
                if nclassdef isa AStdClassdef then
                        var ndoc = nclassdef.n_doc
-                       if ndoc != null then mclassdef.mdoc = ndoc.to_mdoc
+                       if ndoc != null then
+                               var mdoc = ndoc.to_mdoc
+                               mclassdef.mdoc = mdoc
+                               mdoc.original_mentity = mclassdef
+                       end
                end
 
                if mclassdef.is_intro then
index 56ff873..09c13e2 100644 (file)
@@ -293,7 +293,11 @@ redef class APropdef
        private fun set_doc(mpropdef: MPropDef)
        do
                var ndoc = self.n_doc
-               if ndoc != null then mpropdef.mdoc = ndoc.to_mdoc
+               if ndoc != null then
+                       var mdoc = ndoc.to_mdoc
+                       mpropdef.mdoc = mdoc
+                       mdoc.original_mentity = mpropdef
+               end
        end
 
        private fun check_redef_property_visibility(modelbuilder: ModelBuilder, nclassdef: AClassdef, nvisibility: nullable AVisibility, mprop: MProperty)