tests: update sav/nitmetrics_args1.res
[nit.git] / src / doc / doc_base.nit
index e947ee2..6cd6083 100644 (file)
@@ -68,7 +68,7 @@ end
 abstract class DocComposite
 
        # Parent element.
-       var parent: nullable DocComposite = null
+       var parent: nullable DocComposite = null is writable
 
        # Does `self` have a `parent`?
        fun is_root: Bool do return parent == null
@@ -85,8 +85,15 @@ abstract class DocComposite
        #
        # Shortcut for `children.add`.
        fun add_child(child: DocComposite) do
+               child.parent = self
                children.add child
        end
+
+       # Depth of `self` in the composite tree.
+       fun depth: Int do
+               if parent == null then return 0
+               return parent.depth + 1
+       end
 end
 
 # The `DocComposite` element that contains all the other.