From: Alexandre Terrasa Date: Fri, 21 Jun 2013 06:33:38 +0000 (-0400) Subject: ni: now display FT and VT on class doc X-Git-Tag: v0.6.1~73^2~5^2~92 X-Git-Url: http://nitlanguage.org ni: now display FT and VT on class doc Signed-off-by: Alexandre Terrasa --- diff --git a/src/model_utils.nit b/src/model_utils.nit index 6bdc558..545ea69 100644 --- a/src/model_utils.nit +++ b/src/model_utils.nit @@ -115,6 +115,37 @@ redef class MClass return res end + # Get the list of all virtual types available in 'self'. + fun virtual_types: Set[MVirtualTypeProp] do + var res = new HashSet[MVirtualTypeProp] + for mclassdef in mclassdefs do + for mpropdef in mclassdef.mpropdefs do + if mpropdef isa MVirtualTypeDef then + res.add(mpropdef.mproperty) + end + end + end + for ancestor in ancestors do + for mclassdef in ancestor.mclassdefs do + for mpropdef in mclassdef.mpropdefs do + if mpropdef isa MVirtualTypeDef then + res.add(mpropdef.mproperty) + end + end + end + end + return res + end + + # Get the list of all parameter types in 'self'. + fun parameter_types: Map[String, MType] do + var res = new HashMap[String, MType] + for i in [0..intro.parameter_names.length[ do + res[intro.parameter_names[i]] = intro.bound_mtype.arguments[i] + end + return res + end + fun is_class: Bool do return self.kind == concrete_kind or self.kind == abstract_kind end diff --git a/src/ni.nit b/src/ni.nit index 5b6aa9a..1f3a4ba 100644 --- a/src/ni.nit +++ b/src/ni.nit @@ -159,7 +159,25 @@ class NitIndex pager.add_rule pager.addn(nclass.comment.green) pager.add_rule - #TODO VT + if not mclass.parameter_types.is_empty then + pager.add("# formal types\n".bold) + for ft, bound in mclass.parameter_types do + pager.add("\t{ft.to_s.green}: {bound}") + pager.add("") + end + end + if not mclass.virtual_types.is_empty then + pager.add("# virtual types\n".bold) + for vt in mclass.virtual_types do + if vt.visibility.to_s == "public" then pager.add("\t{vt.to_s.green}: {vt.intro.bound.to_s}") + if vt.visibility.to_s == "private" then pager.add("\t{vt.to_s.red}: {vt.intro.bound.to_s}") + if vt.visibility.to_s == "protected" then pager.add("\t{vt.to_s.yellow}: {vt.intro.bound.to_s}") + if vt.intro_mclassdef != mclass.intro then + pager.add("\t\tintroduced in {vt.intro_mclassdef.namespace}::{vt}".gray) + end + pager.add("") + end + end pager.add_rule var cats = new HashMap[String, Collection[MMethod]]