parser: Do not crash if last_loken is unset
[nit.git] / src / nitdoc.nit
index 2bfb3ad..30d29da 100644 (file)
@@ -243,7 +243,7 @@ special AbstractCompiler
                self.extract_other_doc
        end
 
-       redef init
+       init
        do
                super
                option_context.add_option(opt_dir)
@@ -408,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
 
@@ -431,7 +425,7 @@ special MMEntity
 
        redef meth prototype_head(dctx)
        do
-               var res = ""
+               var res = new Buffer
                var intro_class = known_intro_class(dctx)
                var is_redef = local_class != intro_class
 
@@ -450,21 +444,65 @@ special MMEntity
                                res.append(" {intro_class.module.html_link(dctx)}::")
                        end
                end
-               return res
+               return res.to_s
        end
 
        redef meth prototype_body(dctx)
        do
-               var res = signature.to_html(dctx)
+               var res = new Buffer
+               res.append(signature.to_html(dctx))
                var s = self
-               if s isa MMConcreteProperty then
+               if s.node != null then
                        if s.node isa ADeferredMethPropdef then
                                res.append(" is abstract")
                        else if s.node isa AInternMethPropdef then
                                res.append(" is intern")
                        end
                end
-               return res
+               return res.to_s
+       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 n == null or 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
@@ -638,11 +676,11 @@ redef class ADoc
        # Html transcription of the doc
        meth to_html: String
        do
-               var res = new String
+               var res = new Buffer
                for c in n_comment do
                        res.append(c.text.substring_from(1))
                end
-               return res
+               return res.to_s
        end
 
        # Oneliner transcription of the doc
@@ -689,19 +727,19 @@ special MMEntity
 
        redef meth prototype_head(dctx)
        do
-               var res = ""
+               var res = new Buffer
                var ki = known_intro(dctx)
                var is_redef = ki != self
                if is_redef then res.append("redef ")
                if global.visibility_level == 3 then res.append("private ")
                res.append("class ")
                if is_redef then res.append("{ki.module.html_link(dctx)}::")
-               return res
+               return res.to_s
        end
 
        redef meth prototype_body(dctx)
        do
-               var res = ""
+               var res = new Buffer
                if arity > 0 then
                        res.append("[")
                        for i in [0..arity[ do
@@ -712,7 +750,7 @@ special MMEntity
                        end
                        res.append("]")
                end
-               return res
+               return res.to_s
        end
 
        # Extract the doc of a class
@@ -827,20 +865,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
@@ -854,7 +892,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")
 
@@ -888,7 +926,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
@@ -937,7 +975,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
@@ -997,7 +1035,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
@@ -1064,56 +1102,11 @@ redef class MMSrcLocalClass
        end
 end
 
-redef class MMConcreteProperty
-       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
        do
-               var res = new String
+               var res = new Buffer
                if arity > 0 then
                        res.append("(")
                        res.append(self[0].html_link(dctx))
@@ -1127,7 +1120,7 @@ redef class MMSignature
                        res.append(": ")
                        res.append(return_type.html_link(dctx))
                end
-               return res
+               return res.to_s
        end
 end
 
@@ -1143,7 +1136,8 @@ end
 redef class MMTypeGeneric
        redef meth html_link(dctx)
        do
-               var res = local_class.html_link(dctx)
+               var res = new Buffer
+               res.append(local_class.html_link(dctx))
                res.append("[")
                res.append(params[0].html_link(dctx))
                for i in [1..params.length[ do
@@ -1151,7 +1145,7 @@ redef class MMTypeGeneric
                        res.append(params[i].html_link(dctx))
                end
                res.append("]")
-               return res
+               return res.to_s
        end
 end