- for mclassdef in mclass.mclassdefs do
- for mpropdef in mclassdef.mpropdefs do
- if mpropdef isa MAttributeDef then continue
- if mpropdef isa MVirtualTypeDef then cats["virtual types"].add(mpropdef)
- if mpropdef isa MMethodDef then
- if mpropdef.mproperty.is_init then
- cats["constructors"].add(mpropdef)
- else if mpropdef.is_intro then
- cats["introduced methods"].add(mpropdef)
- else
- cats["refined methods"].add(mpropdef)
- end
- end
- end
- end
- # local mproperties
- for cat, list in cats do
- if not list.is_empty then
- #sort list
- var sorted = new Array[MPropDef]
- sorted.add_all(list)
- var sorter = new MPropDefNameSorter
- sorter.sort(sorted)
- pager.add("## {cat}".bold)
- for mpropdef in sorted do
- pager.add("")
- if mbuilder.mpropdef2npropdef.has_key(mpropdef) then
- var nprop = mbuilder.mpropdef2npropdef[mpropdef]
- if not nprop.n_doc == null and not nprop.n_doc.comment.is_empty then
- for comment in nprop.n_doc.comment do pager.add("\t{comment.green}")
- else
- nprop = mbuilder.mpropdef2npropdef[mpropdef.mproperty.intro]
- if not nprop.n_doc == null and not nprop.n_doc.comment.is_empty then
- for comment in nprop.n_doc.comment do pager.add("\t{comment.green}")
- end
- end
- end
- pager.add("\t{mpropdef.to_console}")
- mainmodule.linearize_mpropdefs(mpropdef.mproperty.mpropdefs)
- var previous_defs = new Array[MPropDef]
- for def in mpropdef.mproperty.mpropdefs do
- if def == mpropdef then continue
- if def.is_intro then continue
- if mclass.in_hierarchy(mainmodule) < def.mclassdef.mclass then
- previous_defs.add(def)
- end
- end
- if not mpropdef.is_intro then
- pager.add("\t\t" + "introduced by {mpropdef.mproperty.intro.mclassdef.namespace.bold}".gray)
- end
- if not previous_defs.is_empty then
- for def in previous_defs do pager.add("\t\t" + "inherited from {def.mclassdef.namespace.bold}".gray)
- end
- end
- pager.add("")
- end
- end
- # inherited mproperties
- var inhs = new ArrayMap[MClass, Array[MProperty]]
- var ancestors = mclass.in_hierarchy(mainmodule).greaters.to_a
- mainmodule.linearize_mclasses(ancestors)
- for a in ancestors do
- if a == mclass then continue
- for c in a.mclassdefs do
- for p in c.intro_mproperties do
- if p.intro_mclassdef == c then
- if not inhs.has_key(a) then inhs[a] = new Array[MProperty]
- inhs[a].add(p)
- end
- end
- end
- end
- if not inhs.is_empty then
- pager.add("## inherited properties".bold)
- for a, ps in inhs do
- pager.add("\n\tfrom {a.namespace.bold}: {ps.join(", ")}")
- end
- end
- pager.add_rule
- end
- end
-
- private fun props_fulldoc(pager: Pager, raw_mprops: List[MProperty]) do
- # group by module
- var cats = new HashMap[MModule, Array[MProperty]]
- for mprop in raw_mprops do
- if mprop isa MAttribute then continue
- var key = mprop.intro.mclassdef.mmodule
- if not cats.has_key(key) then cats[key] = new Array[MProperty]
- cats[key].add(mprop)
- end
- #sort groups
- var sorter = new MModuleNameSorter
- var sorted = new Array[MModule]
- sorted.add_all(cats.keys)
- sorter.sort(sorted)
- # display
- for mmodule in sorted do
- var mprops = cats[mmodule]
- pager.add("# matches in module {mmodule.namespace.bold}")
- var sorterp = new MPropertyNameSorter
- sorterp.sort(mprops)
- for mprop in mprops do
- pager.add("")
- if mbuilder.mpropdef2npropdef.has_key(mprop.intro) then
- var nprop = mbuilder.mpropdef2npropdef[mprop.intro]
- if not nprop.n_doc == null and not nprop.n_doc.comment.is_empty then
- for comment in nprop.n_doc.comment do pager.add("\t{comment.green}")
- end
- end
- pager.add("\t{mprop.intro.to_console}")
- pager.add("\t\t" + "introduced in {mprop.intro_mclassdef.namespace.bold}".gray)
- var mpropdefs = mprop.mpropdefs
- mainmodule.linearize_mpropdefs(mpropdefs)
- for mpdef in mpropdefs do
- if not mpdef.is_intro then
- pager.add("\t\t" + "refined in {mpdef.mclassdef.namespace.bold}".gray)
- end
- end
- end
- pager.add_rule
- end
- end
-
- private fun seek_returns(entry: String): List[MProperty] do
- var matches = new List[MProperty]
- for mprop in model.mproperties do
- var intro = mprop.intro
- if intro isa MMethodDef then
- if intro.msignature.return_mtype != null and intro.msignature.return_mtype.to_console.has_prefix(entry) then matches.add(mprop)
- else if intro isa MAttributeDef then
- if intro.static_mtype.to_console.has_prefix(entry) then matches.add(mprop)
- end
- end
- return matches
- end
-
- private fun seek_params(entry: String): List[MProperty] do
- var matches = new List[MProperty]
- for mprop in model.mproperties do
- var intro = mprop.intro
- if intro isa MMethodDef then
- var mparameters = intro.msignature.mparameters
- for mparameter in mparameters do
- print mparameter.mtype.to_console
- if mparameter.mtype.to_console.has_prefix(entry) then matches.add(mprop)
- end
- else if intro isa MAttributeDef then
- if intro.static_mtype.to_console.has_prefix(entry) then matches.add(mprop)
- end
- end
- return matches
- end
-end
-
-# Printing facilities
-
-redef class MModule
- # prototype of the module
- # module ownername::name
- private fun prototype: String do return "module {name}"
-
- # namespace of the module
- # ownername::name
- private fun namespace: String do
- if public_owner == null then
- return self.name
- else
- return "{public_owner.namespace}::{self.name}"
- end
- end
-end
-
-redef class MClass
- # return the generic signature of the class
- # [E, F]
- private fun signature: String do
- var res = new Buffer
- if arity > 0 then
- res.append("[")
- for i in [0..intro.parameter_names.length[ do
- res.append(intro.parameter_names[i])
- if i < intro.parameter_names.length - 1 then res.append(", ")
- end
- res.append("]")