docs: list all existing implements of a method/property
authorDaniel Kolesa <d.kolesa@osg.samsung.com>
Thu, 9 Feb 2017 14:58:22 +0000 (15:58 +0100)
committerDaniel Kolesa <d.kolesa@osg.samsung.com>
Thu, 9 Feb 2017 14:58:52 +0000 (15:58 +0100)
src/scripts/elua/apps/docgen/doctree.lua
src/scripts/elua/apps/gendoc.lua

index c388c0f..042dcab 100644 (file)
@@ -210,7 +210,7 @@ M.Class = Node:clone {
     end,
 
     children_get = function(self)
-        return revh[self:full_name_get()]
+        return revh[self:full_name_get()] or {}
     end,
 
     functions_get = function(self, ft)
@@ -249,6 +249,10 @@ M.Class = Node:clone {
         return M.Node.nspaces_get(self, self:type_str_get(), root)
     end,
 
+    is_same = function(self, other)
+        return self.class == other.class
+    end,
+
     -- static getters
 
     by_name_get = function(name)
@@ -394,6 +398,10 @@ M.Function = Node:clone {
             tbl[#tbl + 1] = not not root
         end
         return tbl
+    end,
+
+    is_same = function(self, other)
+        return self.func == other.func
     end
 }
 
@@ -1413,6 +1421,9 @@ M.parse = function()
     for cl in eolian.all_classes_get() do
         local cln = cl:full_name_get()
         for icl in cl:inherits_get() do
+            if icl == "Elm.List" then
+                print("GOT ELM LIST")
+            end
             local t = revh[icl]
             if not t then
                 t = {}
index a184853..524583a 100644 (file)
@@ -1015,6 +1015,50 @@ local write_inherited_from = function(f, impl, cl, over)
     f:write_i(buf:finish())
 end
 
+local impls_of = {}
+
+local get_all_impls_of
+get_all_impls_of = function(tbl, cl, fn)
+    for i, imp in ipairs(cl:implements_get()) do
+        local ofn = imp:function_get()
+        if ofn:is_same(fn) then
+            tbl[#tbl + 1] = cl
+            break
+        end
+    end
+    for i, cln in ipairs(cl:children_get()) do
+        local icl = dtree.Class.by_name_get(cln)
+        get_all_impls_of(tbl, icl, fn)
+    end
+end
+
+local write_ilist = function(f, impl, cl)
+    local fn = impl:function_get()
+    local fnn = fn:name_get()
+    local ocl = fn:implement_get():class_get()
+    local onm = ocl:full_name_get() .. "." .. fnn
+    local imps = impls_of[onm]
+    if not imps then
+        imps = {}
+        impls_of[onm] = imps
+        get_all_impls_of(imps, ocl, fn)
+    end
+
+    f:write_h("Implemented by", 2)
+    local t = {}
+    for i, icl in ipairs(imps) do
+        local buf = writer.Buffer()
+        local cfn = icl:full_name_get() .. "." .. fnn
+        if icl:is_same(cl) then
+            buf:write_b(cfn)
+        else
+            buf:write_link(fn:nspaces_get(icl, true), cfn)
+        end
+        t[#t + 1] = buf:finish()
+    end
+    f:write_list(t)
+end
+
 build_method = function(impl, cl)
     local over = impl:is_overridden(cl)
     local fn = impl:function_get()
@@ -1051,6 +1095,9 @@ build_method = function(impl, cl)
     f:write_editable(mns, "description")
     f:write_nl()
 
+    write_ilist(f, impl, cl)
+    f:write_nl()
+
     f:finish()
 end
 
@@ -1156,6 +1203,9 @@ build_property = function(impl, cl)
         f:write_nl()
     end
 
+    write_ilist(f, impl, cl)
+    f:write_nl()
+
     f:finish()
 end