ni_nitdoc: display inherited virtual types and constructors in class sidebar
authorAlexandre Terrasa <alexandre@moz-code.org>
Sat, 20 Jul 2013 15:28:43 +0000 (11:28 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Sat, 20 Jul 2013 15:28:43 +0000 (11:28 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/model_utils.nit
src/ni_nitdoc.nit

index 4d8d615..2591da1 100644 (file)
@@ -125,6 +125,17 @@ redef class MClass
                return res
        end
 
+       # Get the set of properties introduced in 'self'.
+       fun intro_mproperties: Set[MProperty] do
+               var res = new HashSet[MProperty]
+               for mclassdef in mclassdefs do
+                       for mpropdef in mclassdef.mpropdefs do
+                               if mpropdef.is_intro then res.add(mpropdef.mproperty)
+                       end
+               end
+               return res
+       end
+
        # Get the list of locally refined methods in 'self'.
        fun redef_methods: Set[MMethod] do
                var res = new HashSet[MMethod]
@@ -138,6 +149,17 @@ redef class MClass
                return res
        end
 
+       # Get the set of locally refined properties in 'self'.
+       fun redef_mproperties: Set[MProperty] do
+               var res = new HashSet[MProperty]
+               for mclassdef in mclassdefs do
+                       for mpropdef in mclassdef.mpropdefs do
+                               if not mpropdef.is_intro then res.add(mpropdef.mproperty)
+                       end
+               end
+               return res
+       end
+
        # Get the list of methods inherited by 'self'.
        fun inherited_methods: Set[MMethod] do
                var res = new HashSet[MMethod]
@@ -149,6 +171,17 @@ redef class MClass
                return res
        end
 
+       # Get the set of all properties inherited by self
+       fun inherited_mproperties: Set[MProperty] do
+               var res = new HashSet[MProperty]
+               for s in ancestors do
+                       for m in s.intro_mproperties do
+                               if not self.intro_mproperties.has(m) and not self.redef_mproperties.has(m) then res.add(m)
+                       end
+               end
+               return res
+       end
+
        # Get the list of all virtual types available in 'self'.
        fun virtual_types: Set[MVirtualTypeProp] do
                var res = new HashSet[MVirtualTypeProp]
index b6232b3..35fe406 100644 (file)
@@ -639,6 +639,10 @@ class NitdocClass
        private var mclass: MClass
        private var mbuilder: ModelBuilder
        private var nitdoc: Nitdoc
+       private var vtypes = new HashSet[MVirtualTypeDef]
+       private var consts = new HashSet[MMethodDef]
+       private var meths = new HashSet[MMethodDef]
+       private var inherited = new HashSet[MPropDef]
 
        init(mclass: MClass, nitdoc: Nitdoc, dot_dir: nullable String, source: nullable String) do
                self.mclass = mclass
@@ -646,6 +650,35 @@ class NitdocClass
                self.nitdoc = nitdoc
                self.dot_dir = dot_dir
                self.source = source
+               # load properties
+               for mclassdef in mclass.mclassdefs do
+                       for mpropdef in mclassdef.mpropdefs do
+                               if mpropdef.mproperty.visibility <= none_visibility then continue
+                               if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
+                               if mpropdef isa MMethodDef then
+                                       if mpropdef.mproperty.is_init then
+                                               consts.add(mpropdef)
+                                       else
+                                               meths.add(mpropdef)
+                                       end
+                               end
+                       end
+               end
+               # get inherited properties
+               for mprop in mclass.inherited_mproperties do
+                       var mpropdef = mprop.intro
+                       if mprop.visibility <= none_visibility then continue
+                       if mprop.intro_mclassdef.mclass.name == "Object" then continue
+                       if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
+                       if mpropdef isa MMethodDef then
+                               if mpropdef.mproperty.is_init then
+                                       consts.add(mpropdef)
+                               else
+                                       meths.add(mpropdef)
+                               end
+                       end
+                       inherited.add(mpropdef)
+               end
        end
 
        redef fun head do
@@ -684,30 +717,6 @@ class NitdocClass
                var sorter = new ComparableSorter[MPropDef]
                append("<nav class='properties filterable'>")
                append("<h3>Properties</h3>")
-               # get intro and redef properties
-               var vtypes = new HashSet[MVirtualTypeDef]
-               var consts = new HashSet[MMethodDef]
-               var meths = new HashSet[MMethodDef]
-               for mclassdef in mclass.mclassdefs do
-                       for mpropdef in mclassdef.mpropdefs do
-                               if mpropdef.mproperty.visibility <= none_visibility then continue
-                               if mpropdef isa MVirtualTypeDef then vtypes.add(mpropdef)
-                               if mpropdef isa MMethodDef then
-                                       if mpropdef.mproperty.is_init then
-                                               consts.add(mpropdef)
-                                       else
-                                               meths.add(mpropdef)
-                                       end
-                               end
-                       end
-               end
-               # get inherited properties
-               for mprop in mclass.inherited_methods do
-                       var mpropdef = mprop.intro
-                       if mprop.visibility <= none_visibility then continue
-                       if mprop.intro_mclassdef.mclass.name == "Object" then continue
-                       meths.add(mpropdef)
-               end
                # virtual types
                if vtypes.length > 0 then
                        var vts = new Array[MVirtualTypeDef]