highlight: fix broken support for `MVirtualType`
[nit.git] / src / highlight.nit
index 757af93..5141fbe 100644 (file)
@@ -60,11 +60,9 @@ class HighlightVisitor
        # It is used to refer to some specific entities when generating links.
        # If `null` is returned, then no link are generated and `<a>` elements become `<span>`.
        #
-       # Clients are encouraged to redefine the method in a subclass to control where entities should link to.
-       fun hrefto(entitiy: MEntity): nullable String
-       do
-               return entitiy.href
-       end
+       # By default, `null` is returned.
+       # Clients are therefore encouraged to redefine the method in a subclass to control where entities should link to.
+       fun hrefto(entitiy: MEntity): nullable String do return null
 
        init
        do
@@ -171,7 +169,7 @@ class HighlightVisitor
                var stack = new Array[Prod]
                var line = 0
                var c: nullable Token = first_token
-               var hv = new HighlightVisitor
+               var hv = self
                while c != null do
                        var starting
 
@@ -428,8 +426,12 @@ redef class MEntity
                return (new HTMLTag("a")).attr("href", href).text(text)
        end
 
-       # Default link
-       private fun href: nullable String do return null
+       # Append an entry for the doc in the given infobox
+       private fun add_doc_to_infobox(res: HInfoBox)
+       do
+               var mdoc = mdoc_or_fallback
+               if mdoc != null then mdoc.fill_infobox(res)
+       end
 end
 
 redef class MModule
@@ -438,8 +440,7 @@ redef class MModule
                var res = new HInfoBox(v, "module {name}")
                res.href = v.hrefto(self)
                res.new_field("module").add(linkto(v))
-               var mdoc = self.mdoc
-               if mdoc != null then mdoc.fill_infobox(res)
+               add_doc_to_infobox(res)
                if in_importation.greaters.length > 1 then
                        var c = res.new_dropdown("imports", "{in_importation.greaters.length-1} modules")
                        for x in in_importation.greaters do
@@ -450,12 +451,6 @@ redef class MModule
                return res
        end
 
-       # The module HTML page
-       redef fun href: String
-       do
-               return c_name + ".html"
-       end
-
        redef fun linkto(v) do return linkto_text(v, name)
 end
 
@@ -470,10 +465,9 @@ redef class MClassDef
                        res.new_field("redef class").text(mclass.name)
                        res.new_field("intro").add mclass.intro.linkto_text(v, "in {mclass.intro_mmodule.to_s}")
                end
-               var mdoc = self.mdoc
-               if mdoc == null then mdoc = mclass.intro.mdoc
-               if mdoc != null then mdoc.fill_infobox(res)
+               add_doc_to_infobox(res)
 
+               var in_hierarchy = self.in_hierarchy
                if in_hierarchy == null then return res
 
                if in_hierarchy.greaters.length > 1 then
@@ -501,12 +495,6 @@ redef class MClassDef
                end
                return res
        end
-
-       # The class HTML page (an anchor in the module page)
-       redef fun href: String
-       do
-               return mmodule.href + "#" + to_s
-       end
 end
 
 redef class MPropDef
@@ -515,10 +503,13 @@ redef class MPropDef
                var res = new HInfoBox(v, to_s)
                res.href = v.hrefto(self)
                if self isa MMethodDef then
+                       var msignature = self.msignature
                        if msignature != null then res.new_field("fun").append(mproperty.name).add msignature.linkto(v)
                else if self isa MAttributeDef then
+                       var static_mtype = self.static_mtype
                        if static_mtype != null then res.new_field("fun").append(mproperty.name).add static_mtype.linkto(v)
                else if self isa MVirtualTypeDef then
+                       var bound = self.bound
                        if bound != null then res.new_field("add").append(mproperty.name).add bound.linkto(v)
                else
                        res.new_field("wat?").append(mproperty.name)
@@ -528,9 +519,7 @@ redef class MPropDef
                else
                        res.new_field("intro").add mproperty.intro.linkto_text(v, "in {mproperty.intro.mclassdef}")
                end
-               var mdoc = self.mdoc
-               if mdoc == null then mdoc = mproperty.intro.mdoc
-               if mdoc != null then mdoc.fill_infobox(res)
+               add_doc_to_infobox(res)
                if mproperty.mpropdefs.length > 1 then
                        var c = res.new_dropdown("redef", "redefinitions")
                        for x in mproperty.mpropdefs do
@@ -540,12 +529,6 @@ redef class MPropDef
 
                return res
        end
-
-       # The property HTML page (an anchor in the module page)
-       redef fun href: String
-       do
-               return self.mclassdef.mmodule.href + "#" + self.to_s
-       end
 end
 
 redef class MClassType
@@ -554,9 +537,7 @@ redef class MClassType
                var res = new HInfoBox(v, to_s)
                res.href = v.hrefto(self)
                res.new_field("class").add mclass.intro.linkto(v)
-               var mdoc = mclass.mdoc
-               if mdoc == null then mdoc = mclass.intro.mdoc
-               if mdoc != null then mdoc.fill_infobox(res)
+               add_doc_to_infobox(res)
                return res
        end
        redef fun linkto(v)
@@ -570,10 +551,8 @@ redef class MVirtualType
                var res = new HInfoBox(v, to_s)
                res.href = v.hrefto(mproperty)
                var p = mproperty
-               var pd = p.intro
-               res.new_field("virtual type").add pd.linkto(v)
-               var mdoc = pd.mdoc
-               if mdoc != null then mdoc.fill_infobox(res)
+               res.new_field("virtual type").add p.intro.linkto(v)
+               add_doc_to_infobox(res)
                return res
        end
        redef fun linkto(v)
@@ -668,9 +647,7 @@ redef class CallSite
                else
                        res.new_field("intro").add mproperty.intro.linkto_text(v, "in {mproperty.intro.mclassdef}")
                end
-               var mdoc = mpropdef.mdoc
-               if mdoc == null then mdoc = mproperty.intro.mdoc
-               if mdoc != null then mdoc.fill_infobox(res)
+               add_doc_to_infobox(res)
 
                return res
        end
@@ -719,6 +696,8 @@ redef class AQclassid
        redef fun decorate_tag(v, res, token)
        do
                if token != n_id then return null
+               var parent = self.parent
+               if parent == null then return null
                return parent.decorate_tag(v, res, token)
        end
 end
@@ -727,6 +706,8 @@ redef class AQid
        redef fun decorate_tag(v, res, token)
        do
                if token != n_id then return null
+               var parent = self.parent
+               if parent == null then return null
                return parent.decorate_tag(v, res, token)
        end
 end
@@ -781,7 +762,7 @@ end
 redef class Token
        # Produce an HTMLTag with the correct contents and CSS classes
        # Subclasses can redefine it to decorate the tag
-       redef fun make_tag(v: HighlightVisitor): HTMLTag
+       redef fun make_tag(v): HTMLTag
        do
                var res = new HTMLTag("span")
                res.text(text)
@@ -875,6 +856,7 @@ end
 redef class ASendExpr
        redef fun decorate_tag(v, res, token)
        do
+               var callsite = self.callsite
                if callsite == null then return null
                return callsite.infobox(v)
        end
@@ -883,6 +865,7 @@ end
 redef class ANewExpr
        redef fun decorate_tag(v, res, token)
        do
+               var callsite = self.callsite
                if callsite == null then return null
                return callsite.infobox(v)
        end
@@ -903,7 +886,9 @@ end
 redef class AModuleName
        redef fun decorate_tag(v, res, token)
        do
-               return parent.decorate_tag(v, res, token)
+               var p = parent
+               if p == null then return null
+               return p.decorate_tag(v, res, token)
        end
 end
 
@@ -1016,6 +1001,7 @@ redef class AFormaldef
        do
                if not token isa TClassid then return null
                res.add_class("nc_vt")
+               var mtype = self.mtype
                if mtype == null then return null
                return mtype.infobox(v)
        end