Prepare Nit code for inherited and automatic constructors.
[nit.git] / src / nitdoc.nit
index fbd2c85..46cd1ed 100644 (file)
@@ -24,7 +24,7 @@ import abstracttool
 
 # Store knowledge and facilities to generate files
 class DocContext
-special ToolContext
+special AbstractCompiler
        # Destination directory
        readable writable attr _dir: String
 
@@ -92,8 +92,6 @@ special ToolContext
                _stage_context = new StageContext(null)
        end
 
-       redef init do end
-
        # Generate common files (frames, index, overview)
        meth extract_other_doc
        do
@@ -231,6 +229,32 @@ special ToolContext
                        return res
                end
        end
+
+       readable attr _opt_dir: OptionString = new OptionString("Directory where doc is generated", "-d", "--dir")
+
+       redef meth perform_work(mods)
+       do
+               dir.mkdir
+
+               for mod in modules do
+                       assert mod isa MMSrcModule
+                       mod.extract_module_doc(self)
+               end
+               self.extract_other_doc
+       end
+
+       init
+       do
+               super
+               option_context.add_option(opt_dir)
+       end
+
+       redef meth process_options
+       do
+               super
+               dir = opt_dir.value
+               if dir == null then dir = "."
+       end
 end
 
 # Conditionnal part of the text content of a DocContext
@@ -384,12 +408,6 @@ special MMEntity
                end
        end
        
-       redef meth short_doc do return concrete_property.short_doc
-
-       redef meth doc do return concrete_property.doc
-
-       redef meth need_doc(dctx) do return false
-
        # Kind of property (meth, attr, etc.)
        meth kind: String is abstract
 
@@ -433,7 +451,7 @@ special MMEntity
        do
                var res = signature.to_html(dctx)
                var s = self
-               if s isa MMSrcLocalProperty then
+               if s.node != null then
                        if s.node isa ADeferredMethPropdef then
                                res.append(" is abstract")
                        else if s.node isa AInternMethPropdef then
@@ -442,6 +460,49 @@ special MMEntity
                end
                return res
        end
+
+       redef meth need_doc(dctx)
+       do
+               if global.visibility_level >= 3 or self isa MMAttribute then
+                       if not dctx.intrude_mode then return false
+                       if dctx.module.visibility_for(module) == 0 then return false
+               end
+               if global.intro == self then
+                       return true
+               end
+               return doc != null
+       end
+
+       redef meth short_doc
+       do
+               var d = doc
+               if d != null then
+                       return d.short
+               else if global.intro == self then
+                       return " "
+               else
+                       return global.intro.short_doc
+               end
+       end
+       
+       redef meth doc
+       do
+               var n = node
+               if not node isa PPropdef then
+                       return null
+               end
+               assert n isa PPropdef
+               var d = n.n_doc
+               assert d isa ADoc
+               if d == null then
+                       return null
+               end
+               if d.n_comment.is_empty then
+                       return null
+               else
+                       return d
+               end
+       end
 end
 redef class MMMethod
        redef meth kind do return if global.is_init then "init" else "meth"
@@ -454,20 +515,9 @@ redef class MMTypeProperty
 end
 
 redef class MMSrcModule
-       # Extract doc for the module and its supermodules 
-       meth extract_all_modules_doc(dctx: DocContext)
-       do
-               for m in mhe.greaters_and_self do
-                       assert m isa MMSrcModule
-                       m.extract_module_doc(dctx)
-               end
-       end     
-
-       # Extract and generate html file fhe the module
+       # Extract and generate html file for the module
        meth extract_module_doc(dctx: DocContext)
        do
-               if dctx.modules.has(self) then return
-
                dctx.register(self)
 
                dctx.clear
@@ -814,20 +864,20 @@ special MMEntity
                var passname = pass_name(pass)
                dctx.open_stage
                dctx.stage("<table border=\"1\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\">\n")
-               dctx.stage("<tr bgcolor=\"#CCCCFF\"><th colspan=\"2\">{passname} Summary of {self}</th><tr>\n")
+               dctx.stage("<tr bgcolor=\"#CCCCFF\"><th colspan=\"2\">{passname} Summary of {self}</th></tr>\n")
 
                var new_props = new Array[MMLocalProperty]
                for g in global_properties do
                        if not accept_prop(g.intro, pass) then continue
                        if module.visibility_for(g.intro.module) < g.visibility_level then continue
                        var p = self[g]
-                       if not p.need_doc(dctx) then
+                       if p.local_class != self or not p.need_doc(dctx) then
                                var cla = new Array[MMLocalClass]
                                for m in dctx.owned_modules do
                                        var c = m[global]
                                        if c == null or not c isa MMConcreteClass then continue
                                        var p2 = c[g]
-                                       if p2 == null or not p2.need_doc(dctx) then continue
+                                       if p2 == null or p2.local_class != c or not p2.need_doc(dctx) then continue
                                        cla.add(c)
                                end
                                if cla.is_empty then continue
@@ -841,7 +891,7 @@ special MMEntity
                end
                dctx.sort(new_props)
                for p in new_props do
-                       dctx.add("<tr><td width=\"20%\" align=\"right\">{p.prototype_head(dctx)}</td><td><b>{p.html_link(dctx)}</b>{p.prototype_body(dctx)}<br/>&nbsp;&nbsp;&nbsp;&nbsp;{p.short_doc}</td><tr>\n")
+                       dctx.add("<tr><td width=\"20%\" align=\"right\">{p.prototype_head(dctx)}</td><td><b>{p.html_link(dctx)}</b>{p.prototype_body(dctx)}<br/>&nbsp;&nbsp;&nbsp;&nbsp;{p.short_doc}</td></tr>\n")
                end
                dctx.stage("</table><br/>\n")
 
@@ -875,7 +925,7 @@ special MMEntity
                                        end
                                        for g in c.global_properties do
                                                var p = c[g]
-                                               if p.need_doc(dctx) and accept_prop(p, pass) then
+                                               if p.local_class == c and p.need_doc(dctx) and accept_prop(p, pass) then
                                                        props.add(kc[g])
                                                end
                                        end
@@ -924,7 +974,7 @@ special MMEntity
                        end
                        for g in c.global_properties do
                                var p = c[g]
-                               if p.need_doc(dctx) and accept_prop(p, pass) then
+                               if p.local_class == c and p.need_doc(dctx) and accept_prop(p, pass) then
                                        var kp = kc[g]
                                        if not props.has(kp) then props.add(kp)
                                end
@@ -984,7 +1034,7 @@ special MMEntity
                var properties = new Array[String]
                for g in global_properties do
                        var p = self[g]
-                       if p.need_doc(dctx) and accept_prop(p, pass) then
+                       if p.local_class == self and p.need_doc(dctx) and accept_prop(p, pass) then
                                properties.add(p.html_link(dctx))
                        end
                end
@@ -1051,51 +1101,6 @@ redef class MMSrcLocalClass
        end
 end
 
-redef class MMSrcLocalProperty
-       redef meth need_doc(dctx)
-       do
-               if global.visibility_level >= 3 or self isa MMAttribute then
-                       if not dctx.intrude_mode then return false
-                       if dctx.module.visibility_for(module) == 0 then return false
-               end
-               if global.intro == self then
-                       return true
-               end
-               return true
-       end
-
-       redef meth short_doc
-       do
-               var d = doc
-               if d != null then
-                       return d.short
-               else if global.intro == self then
-                       return "&nbsp;"
-               else
-                       return global.intro.short_doc
-               end
-       end
-       
-       redef meth doc
-       do
-               var n = node
-               if not node isa PPropdef then
-                       return null
-               end
-               assert n isa PPropdef
-               var d = n.n_doc
-               assert d isa ADoc
-               if d == null then
-                       return null
-               end
-               if d.n_comment.is_empty then
-                       return null
-               else
-                       return d
-               end
-       end
-end
-
 redef class MMSignature
        # Htlm transcription of the signature (with nested links)
        meth to_html(dctx: DocContext): String
@@ -1142,42 +1147,5 @@ redef class MMTypeGeneric
        end
 end
 
-
-# The main class of the nitdoc program
-class NitDoc
-special AbstractCompiler
-       readable attr _opt_dir: OptionString = new OptionString("Directory where doc is generated", "-d", "--dir")
-
-       redef meth perform_work(mods)
-       do
-               var dctx = tc
-               assert dctx isa DocContext
-
-               dctx.dir.mkdir
-
-               for mod in mods do
-                       assert mod isa MMSrcModule
-                       mod.extract_all_modules_doc(dctx)
-               end
-               dctx.extract_other_doc
-       end
-
-       redef init
-       do
-               super
-               option_context.add_option(opt_dir)
-       end
-
-       redef meth process_options
-       do
-               super
-               var dctx = new DocContext
-               dctx.dir = opt_dir.value
-               if dctx.dir == null then dctx.dir = "."
-
-               tc = dctx
-       end
-end
-
-var c = new NitDoc
+var c = new DocContext
 c.exec_cmd_line