X-Git-Url: http://nitlanguage.org diff --git a/src/ni_nitdoc.nit b/src/ni_nitdoc.nit index c971c74..8b6a8e5 100644 --- a/src/ni_nitdoc.nit +++ b/src/ni_nitdoc.nit @@ -18,16 +18,18 @@ module ni_nitdoc import model_utils import abstract_compiler -import html class Nitdoc private var toolcontext: ToolContext private var model: Model private var modelbuilder: ModelBuilder private var mainmodule: MModule + private var class_hierarchy: POSet[MClass] private var arguments: Array[String] - private var destinationdir: nullable String - private var sharedir: nullable String + private var output_dir: nullable String + private var dot_dir: nullable String + private var share_dir: nullable String + private var source: nullable String private var opt_dir = new OptionString("Directory where doc is generated", "-d", "--dir") private var opt_source = new OptionString("What link for source (%f for filename, %l for first line, %L for last line)", "--source") @@ -38,10 +40,12 @@ class Nitdoc # We need a model to collect stufs self.toolcontext = toolcontext self.arguments = toolcontext.option_context.rest + toolcontext.option_context.options.clear toolcontext.option_context.add_option(opt_dir) toolcontext.option_context.add_option(opt_source) toolcontext.option_context.add_option(opt_sharedir) toolcontext.option_context.add_option(opt_nodot) + toolcontext.process_options process_options if arguments.length < 1 then @@ -58,16 +62,17 @@ class Nitdoc modelbuilder.full_propdef_semantic_analysis assert mmodules.length == 1 self.mainmodule = mmodules.first + self.class_hierarchy = mainmodule.flatten_mclass_hierarchy end private fun process_options do if not opt_dir.value is null then - destinationdir = opt_dir.value + output_dir = opt_dir.value else - destinationdir = "nitdoc_directory" + output_dir = "doc" end if not opt_sharedir.value is null then - sharedir = opt_sharedir.value + share_dir = opt_sharedir.value else var dir = "NIT_DIR".environ if dir.is_empty then @@ -75,239 +80,1284 @@ class Nitdoc else dir = "{dir}/share/nitdoc" end - sharedir = dir - if sharedir is null then + share_dir = dir + if share_dir is null then print "Error: Cannot locate nitdoc share files. Uses --sharedir or envvar NIT_DIR" abort end - dir = "{sharedir.to_s}/scripts/js-facilities.js" - if sharedir is null then + dir = "{share_dir.to_s}/scripts/js-facilities.js" + if share_dir is null then print "Error: Invalid nitdoc share files. Check --sharedir or envvar NIT_DIR" abort end end + if not opt_source.value is null then + source = "" + else + source = opt_source.value + end end fun start do if arguments.length == 1 then # Create destination dir if it's necessary - if not destinationdir.file_exists then destinationdir.mkdir - sys.system("cp -r {sharedir.to_s}/* {destinationdir.to_s}/") + if not output_dir.file_exists then output_dir.mkdir + sys.system("cp -r {share_dir.to_s}/* {output_dir.to_s}/") + self.dot_dir = null + if not opt_nodot.value then self.dot_dir = output_dir.to_s overview - fullindex + #fullindex + modules + classes + #quicksearch_list end end fun overview do - var overviewpage = new NitdocOverview.with(modelbuilder.nmodules, self.opt_nodot.value, destinationdir.to_s) - overviewpage.save("{destinationdir.to_s}/index.html") + var overviewpage = new NitdocOverview(modelbuilder, dot_dir) + overviewpage.save("{output_dir.to_s}/index.html") end fun fullindex do - var fullindex = new NitdocFullindex.with(model.mmodules) - fullindex.save("{destinationdir.to_s}/full-index.html") + var fullindex = new NitdocFullindex(model.mmodules) + fullindex.save("{output_dir.to_s}/full-index.html") + end + + fun modules do + for mmodule in model.mmodules do + var modulepage = new NitdocModule(mmodule, modelbuilder, dot_dir) + modulepage.save("{output_dir.to_s}/{mmodule.name}.html") + end + end + + fun classes do + for mclass in modelbuilder.model.mclasses do + var classpage = new NitdocClass(mclass, self, dot_dir, source) + classpage.save("{output_dir.to_s}/{mclass.name}.html") + end + end + + # Generate QuickSearch file + fun quicksearch_list do + var file = new OFStream.open("{output_dir.to_s}/quicksearch-list.js") + var content = new Buffer + content.append("var entries = \{ ") + for prop in model.mproperties do + if not prop isa MMethod then continue + content.append("\"{prop.name}\": [") + for propdef in prop.mpropdefs do + content.append("\{txt: \"{propdef.mproperty.full_name}\", url:\"{propdef.mproperty.anchor}\" \}") + if not propdef is prop.mpropdefs.last then content.append(", ") + end + content.append("]") + content.append(", ") + end + + for mclass in model.mclasses do + content.append("\"{mclass.name}\": [") + for mclassdef in mclass.mclassdefs do + content.append("\{txt: \"{mclassdef.mclass.full_name}\", url:\"{mclass.link_anchor}\" \}") + if not mclassdef is mclass.mclassdefs.last then content.append(", ") + end + content.append("]") + if not mclass is model.mclasses.last then content.append(", ") + end + + content.append(" \};") + file.write(content.to_s) + file.close + end + +end + +# Nitdoc base page +abstract class NitdocPage + + var dot_dir: nullable String + var source: nullable String + + init do end + + fun append(str: String) do html.append(str) + var html = new Buffer + + fun head do + append("") + append("") + append("") + append("") + append("") + end + + fun menu is abstract + + fun header do + append("
") + append("") + append("
") + end + + fun content is abstract + + fun footer do + append("") + end + + # Generate a clickable graphviz image using a dot content + fun generate_dot(dot: String, name: String, alt: String) do + var output_dir = dot_dir + if output_dir == null then return + var file = new OFStream.open("{output_dir}/{name}.dot") + file.write(dot) + file.close + sys.system("\{ test -f {output_dir}/{name}.png && test -f {output_dir}/{name}.s.dot && diff {output_dir}/{name}.dot {output_dir}/{name}.s.dot >/dev/null 2>&1 ; \} || \{ cp {output_dir}/{name}.dot {output_dir}/{name}.s.dot && dot -Tpng -o{output_dir}/{name}.png -Tcmapx -o{output_dir}/{name}.map {output_dir}/{name}.s.dot ; \}") + append("
") + append("{alt}") + append("
") + var fmap = new IFStream.open("{output_dir}/{name}.map") + append(fmap.read_all) + fmap.close + end + + # Add a (source) link for a given location + fun show_source(l: Location): String + do + if source == null then + return "({l.file.filename.simplify_path})" + else + # THIS IS JUST UGLY ! (but there is no replace yet) + var x = source.split_with("%f") + source = x.join(l.file.filename.simplify_path) + x = source.split_with("%l") + source = x.join(l.line_start.to_s) + x = source.split_with("%L") + source = x.join(l.line_end.to_s) + return " (show code)" + end + end + + # Render the page as a html string + fun render: String do + append("") + append("") + head + append("") + append("") + header + append("
") + content + append("
") + footer + append("") + return html.to_s end + # Save html page in the specified file + fun save(file: String) do + var out = new OFStream.open(file) + out.write(render) + out.close + end end +# The overview page class NitdocOverview super NitdocPage + private var mbuilder: ModelBuilder + private var mmodules = new Array[MModule] - var amodules: Array[AModule] - - # Init with Array[AModule] to get all ifnormations about each MModule containt in a program - # opt_nodot to inform about the graph gen - # destination: to know where will be saved dot files - init with(modules: Array[AModule], opt_nodot: Bool, destination: String) do - self.amodules = modules - self.opt_nodot = opt_nodot - self.destinationdir = destination + init(mbuilder: ModelBuilder, dot_dir: nullable String) do + self.mbuilder = mbuilder + self.dot_dir = dot_dir + # get modules + var mmodules = new HashSet[MModule] + for mmodule in mbuilder.model.mmodules do + var owner = mmodule.public_owner + if owner != null then + mmodules.add(owner) + else + mmodules.add(mmodule) + end + end + # sort modules + var sorter = new ComparableSorter[MModule] + self.mmodules.add_all(mmodules) + sorter.sort(self.mmodules) end redef fun head do super - add("title").text("Overview | Nit Standard Library") - end - - redef fun header do - open("header") - open("nav").add_class("main") - open("ul") - add("li").add_class("current").text("Overview") - open("li") - add_html("Full Index") - close("li") - open("li").attr("id", "liGitHub") - open("a").add_class("btn").attr("id", "logGitHub") - add("img").attr("id", "imgGitHub").attr("src", "resources/icons/github-icon.png") - close("a") - open("div").add_class("popover bottom") - add("div").add_class("arrow").text(" ") - open("div").add_class("githubTitle") - add("h3").text("Github Sign In") - close("div") - open("div") - add("label").attr("id", "lbloginGit").text("Username") - add("input").attr("id", "loginGit").attr("name", "login").attr("type", "text") - open("label").attr("id", "logginMessage").text("Hello ") - open("a").attr("id", "githubAccount") - add("strong").attr("id", "nickName").text(" ") - close("a") - close("label") - close("div") - open("div") - add("label").attr("id", "lbpasswordGit").text("Password") - add("input").attr("id", "passwordGit").attr("name", "password").attr("type", "password") - open("div").attr("id", "listBranches") - add("label").attr("id", "lbBranches").text("Branch") - add("select").add_class("dropdown").attr("id", "dropBranches").attr("name", "dropBranches").attr("tabindex", "1").text(" ") - close("div") - close("div") - open("div") - add("label").attr("id", "lbrepositoryGit").text("Repository") - add("input").attr("id", "repositoryGit").attr("name", "repository").attr("type", "text") - close("div") - open("div") - add("label").attr("id", "lbbranchGit").text("Branch") - add("input").attr("id", "branchGit").attr("name", "branch").attr("type", "text") - close("div") - open("div") - add("a").attr("id", "signIn").text("Sign In") - close("div") - close("div") - close("li") - close("ul") - close("nav") - close("header") - end - - redef fun body do - super - open("div").add_class("page") - open("div").add_class("content fullpage") - add("h1").text("Nit Standard Library") - open("article").add_class("overview") - add_html("

Documentation for the standard library of Nit
Version jenkins-component=stdlib-19
Date: TODAY

") - close("article") - open("article").add_class("overview") - add("h2").text("Modules") - open("ul") - add_modules - close("ul") - process_generate_dot - close("article") - close("div") - close("div") - add("footer").text("Nit standard library. Version jenkins-component=stdlib-19.") + append("Overview | Nit Standard Library") end - fun add_modules do - var ls = new List[nullable MModule] - for amodule in amodules do - var mmodule = amodule.mmodule.public_owner - if mmodule != null and not ls.has(mmodule) then - open("li") - add("a").attr("href", "{mmodule.name}.html").text("{mmodule.to_s} ") - add_html(amodule.comment) - close("li") - ls.add(mmodule) - end + redef fun menu do + append("
  • Overview
  • ") + append("
  • Full Index
  • ") + end + + redef fun content do + append("
    ") + append("

    Nit Standard Library

    ") + append("

    Documentation for the standard library of Nit
    Version jenkins-component=stdlib-19
    Date: TODAY

    ") + append("
    ") + # module list + append("

    Modules

    ") + append("") + # module graph + process_generate_dot + append("
    ") + append("
    ") end fun process_generate_dot do var op = new Buffer op.append("digraph dep \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n") - for amodule in amodules do - op.append("\"{amodule.mmodule.name}\"[URL=\"{amodule.mmodule.name}.html\"];\n") - for mmodule2 in amodule.mmodule.in_importation.direct_greaters do - op.append("\"{amodule.mmodule.name}\"->\"{mmodule2.name}\";\n") + for mmodule in mmodules do + op.append("\"{mmodule.name}\"[URL=\"{mmodule.name}.html\"];\n") + for imported in mmodule.in_importation.direct_greaters do + if imported.direct_owner == null then + op.append("\"{mmodule.name}\"->\"{imported.name}\";\n") + end end end op.append("\}\n") generate_dot(op.to_s, "dep", "Modules hierarchy") end - end +# The full index page class NitdocFullindex super NitdocPage - var mmodules: Array[MModule] + private var mmodules: Array[MModule] - init with(mmodules: Array[MModule]) do + init(mmodules: Array[MModule]) do self.mmodules = mmodules - opt_nodot = false - destinationdir = "" + self.dot_dir = null end redef fun head do super - add("title").text("Full Index | Nit Standard Library") + append("Full Index | Nit Standard Library") + end + + redef fun menu do + append("
  • Overview
  • ") + append("
  • Full Index
  • ") + end + + redef fun content do + append("
    ") + append("

    Full Index

    ") + module_column + classes_column + properties_column + append("
    ") + end + + # Add to content modules column + fun module_column do + var ls = new List[nullable MModule] + var sorted = mmodules + var sorterp = new ComparableSorter[MModule] + sorterp.sort(sorted) + append("
    ") + append("

    Modules

    ") + append("") + append("") + end + + # Add to content classes modules + fun classes_column do + var sorted = mmodules.first.imported_mclasses.to_a + var sorterp = new ComparableSorter[MClass] + sorterp.sort(sorted) + append("
    ") + append("

    Classes

    ") + append("") + append("
    ") + end + + # Insert the properties column of fullindex page + fun properties_column do + append("
    ") + append("

    Properties

    ") + append("") + append("
    ") end end -class NitdocPage - super HTMLPage +# A module page +class NitdocModule + super NitdocPage + + private var mmodule: MModule + private var mbuilder: ModelBuilder - var opt_nodot: Bool - var destinationdir : String + init(mmodule: MModule, mbuilder: ModelBuilder, dot_dir: nullable String) do + self.mmodule = mmodule + self.mbuilder = mbuilder + self.dot_dir = dot_dir + end redef fun head do - add("meta").attr("charset", "utf-8") - add("script").attr("type", "text/javascript").attr("src", "scripts/jquery-1.7.1.min.js") - add("script").attr("type", "text/javascript").attr("src", "quicksearch-list.js") - add("script").attr("type", "text/javascript").attr("src", "scripts/js-facilities.js") - add("link").attr("rel", "stylesheet").attr("href", "styles/main.css").attr("type", "text/css").attr("media", "screen") + super + var amodule = mbuilder.mmodule2nmodule[mmodule] + append("{mmodule.name} module | {amodule.short_comment}") end - redef fun body do header - fun header do end + redef fun menu do + append("
  • Overview
  • ") + append("
  • {mmodule.name}
  • ") + append("
  • Full Index
  • ") + end - # Generate a clickable graphviz image using a dot content - fun generate_dot(dot: String, name: String, alt: String) do - if opt_nodot then return - var file = new OFStream.open("{self.destinationdir}/{name}.dot") - file.write(dot) - file.close - sys.system("\{ test -f {self.destinationdir}/{name}.png && test -f {self.destinationdir}/{name}.s.dot && diff {self.destinationdir}/{name}.dot {self.destinationdir}/{name}.s.dot >/dev/null 2>&1 ; \} || \{ cp {self.destinationdir}/{name}.dot {self.destinationdir}/{name}.s.dot && dot -Tpng -o{self.destinationdir}/{name}.png -Tcmapx -o{self.destinationdir}/{name}.map {self.destinationdir}/{name}.s.dot ; \}") - open("article").add_class("graph") - add("img").attr("src", "{name}.png").attr("usemap", "#{name}").attr("style", "margin:auto").attr("alt", "{alt}") - close("article") - var fmap = new IFStream.open("{self.destinationdir}/{name}.map") - add_html(fmap.read_all) - fmap.close + redef fun content do + sidebar + append("
    ") + append("

    {mmodule.name}

    ") + append("
    {mmodule.html_signature(mbuilder)}
    ") + append(mmodule.html_full_comment(mbuilder)) + process_generate_dot + classes + properties + append("
    ") + end + + fun process_generate_dot do + var name = "dep_{mmodule.name}" + var op = new Buffer + op.append("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n") + for m in mmodule.in_importation.poset do + var public_owner = m.public_owner + if public_owner == null then + public_owner = m + if m == mmodule then + op.append("\"{m.name}\"[shape=box,margin=0.03];\n") + else + op.append("\"{m.name}\"[URL=\"{m.name}.html\"];\n") + end + end + for imported in m.in_importation.direct_greaters do + if imported.public_owner == null then + op.append("\"{public_owner.name}\"->\"{imported.name}\";\n") + end + end + end + op.append("\}\n") + generate_dot(op.to_s, name, "Dependency graph for module {mmodule.name}") end + fun sidebar do + var amodule = mbuilder.mmodule2nmodule[mmodule] + append("") + end + + private fun display_module_list(list: Array[MModule]) do + append("") + end + + fun classes do + var amodule = mbuilder.mmodule2nmodule[mmodule] + var intro_mclasses = mmodule.intro_mclasses + var redef_mclasses = mmodule.redef_mclasses + var all_mclasses = new HashSet[MClass] + for m in mmodule.in_nesting.greaters do + all_mclasses.add_all(m.intro_mclasses) + all_mclasses.add_all(m.redef_mclasses) + end + all_mclasses.add_all(intro_mclasses) + all_mclasses.add_all(redef_mclasses) + + var sorted = new Array[MClass] + sorted.add_all(all_mclasses) + var sorter = new ComparableSorter[MClass] + sorter.sort(sorted) + append("
    ") + append("
    ") + append("

    Classes

    ") + append("") + append("
    ") + append("
    ") + end + + fun properties do + var amodule = mbuilder.mmodule2nmodule[mmodule] + var mpropdefs = new HashSet[MPropDef] + for m in mmodule.in_nesting.greaters do + for c in m.mclassdefs do mpropdefs.add_all(c.mpropdefs) + end + for c in mmodule.mclassdefs do mpropdefs.add_all(c.mpropdefs) + var sorted = mpropdefs.to_a + var sorter = new ComparableSorter[MPropDef] + sorter.sort(sorted) + append("
    ") + append("

    Properties

    ") + append("") + append("
    ") + end +end + +# A class page +class NitdocClass + super NitdocPage + + private var mclass: MClass + private var mbuilder: ModelBuilder + private var nitdoc: Nitdoc + + init(mclass: MClass, nitdoc: Nitdoc, dot_dir: nullable String, source: nullable String) do + self.mclass = mclass + self.mbuilder = nitdoc.modelbuilder + self.nitdoc = nitdoc + self.dot_dir = dot_dir + self.source = source + end + + redef fun head do + super + var nclass = mbuilder.mclassdef2nclassdef[mclass.intro] + if nclass isa AStdClassdef then + append("{mclass.name} class | {nclass.short_comment}") + else + append("{mclass.name} class") + end + end + + redef fun menu do + append("
  • Overview
  • ") + var public_owner = mclass.public_owner + if public_owner is null then + append("
  • {mclass.intro_mmodule.link(mbuilder)}
  • ") + else + append("
  • {public_owner.link(mbuilder)}
  • ") + end + append("
  • {mclass.name}
  • ") + append("
  • Full Index
  • ") + end + + redef fun content do + append("") + append("
    ") + class_doc + append("
    ") + end + + fun properties_column do + var sorter = new ComparableSorter[MPropDef] + append("") + end + + private fun display_mpropdef_list(list: Array[MPropDef]) do + append("") + end + + fun inheritance_column do + var sorted = new Array[MClass] + var sorterp = new ComparableSorter[MClass] + append("") + end + + fun class_doc do + # title + append("

    {mclass.to_s}

    ") + append("
    ") + var subtitle = "" + if mclass.visibility is none_visibility then subtitle += "private " + subtitle += "{mclass.kind} {mclass.public_owner.html_namespace(mbuilder)}::{mclass}" + append(subtitle) + append("
    ") + # comment + var nclass = mbuilder.mclassdef2nclassdef[mclass.intro] + append("
    ") + append("
    ") + if nclass isa AStdClassdef and not nclass.comment.is_empty then append("
    {nclass.comment}
    CancelCommit
    ")
    +		process_generate_dot
    +		append("
    ") + # concerns + var sorted = new Array[MModule] + sorted.add_all(mclass.concerns.keys) + var sorterp = new ComparableSorter[MModule] + sorterp.sort(sorted) + append("
    ") + append("

    Concerns

    ") + append("") + append("
    ") + # properties + var sorterprop = new ComparableSorter[MProperty] + var sorterc = new ComparableSorter[MClass] + var lmmodule = new List[MModule] + # virtual and formal types + if mclass.virtual_types.length > 0 or mclass.arity > 0 then + append("
    ") + append("

    Formal and Virtual Types

    ") + if mclass.virtual_types.length > 0 then for prop in mclass.virtual_types do description(prop) + #TODO this is incorrect + if mclass.arity > 0 and nclass isa AStdClassdef then + for prop in nclass.n_formaldefs do + append("
    ") + append("

    {prop.collect_text}: nullable ") + append("Object") + append("

    ") + append("
    formal generic type
    ") + append("
    ") + end + end + append("
    ") + end + # constructors + if mclass.constructors.length > 0 then + var sortedc = mclass.constructors.to_a + sorterprop.sort(sortedc) + append("
    ") + append("

    Constructors

    ") + for prop in sortedc do description(prop) + append("
    ") + end + # methods + append("
    ") + append("

    Methods

    ") + for mmodule, mmethods in mclass.all_methods do + var nmodule = mbuilder.mmodule2nmodule[mmodule] + append("") + if mmodule != mclass.intro_mmodule and mmodule != mclass.public_owner then + if mclass.has_mmodule(mmodule) then + append("

    {mmodule.name}: {nmodule.short_comment}

    ") + else + append("

    Methods refined in {mmodule.link(mbuilder)}

    {mmodule.name}: {nmodule.short_comment}

    ") + end + end + var sortedc = mmethods.to_a + sorterprop.sort(sortedc) + for prop in sortedc do description(prop) + end + # inherited methods + if mclass.inherited_methods.length > 0 then + var sortedc = new Array[MClass] + sortedc.add_all(mclass.inherited.keys) + sorterc.sort(sortedc) + append("

    Inherited Methods

    ") + for imclass in sortedc do + var inclass = mbuilder.mclassdef2nclassdef[imclass.intro].as(AStdClassdef) + var sortedp = mclass.inherited[imclass].to_a + sorterprop.sort(sortedp) + append("

    Defined in {imclass.link(inclass)}: ") + for method in sortedp do + #TODO link to inherited propdef + append("{method.name}") + if method != sortedp.last then append(", ") + end + append("

    ") + end + end + append("
    ") + end + + fun description(prop: MProperty) do + if not mbuilder.mpropdef2npropdef.has_key(prop.intro) then return + var nprop = mbuilder.mpropdef2npropdef[prop.intro] + if not nprop isa AMethPropdef then return + var classes = new Array[String] + if nprop isa AInitPropdef then + classes.add("init") + else + classes.add("fun") + end + if prop.is_redef then classes.add("redef") + if prop.visibility == none_visibility then + classes.add("private") + else if prop.visibility == protected_visibility then + classes.add("protected") + else + classes.add("public") + end + append("
    ") + var sign = prop.name + append("

    {prop.name}{nprop.signature}

    ") + append("
    ") + append("{if prop.is_redef then "redef" else ""} fun {prop.intro_mclassdef.namespace(mclass)}::{prop.name}
    ") + append("
    ") + append("
    ") + if nprop.comment == "" then + append("New Comment") + else + append("
    {nprop.comment}
    ") + end + append("CancelCommit
    ")
    +		append("

    ") + if prop.local_class != mclass then + var mredef = prop.local_class.intro_mmodule + append("inherited from {mredef.link(mbuilder)} ") + end + #TODO display show code if doc github + var mintro = prop.intro_mclassdef.mmodule + append("defined by the module {mintro.link(mbuilder)}{if prop.apropdef is null then "" else show_source(prop.apropdef.location)}.") + + for parent in mclass.parents do + var mparent = parent.intro_mmodule + if prop isa MMethod then if parent.constructors.has(prop) then append(" Previously defined by: {mparent.link(mbuilder)} for {parent.name}.") + end + append("

    ") + append("
    ") + append("
    ") + end + + fun process_generate_dot do + var pe = nitdoc.class_hierarchy[mclass] + var cla = new HashSet[MClass] + var sm = new HashSet[MClass] + var sm2 = new HashSet[MClass] + sm.add(mclass) + while cla.length + sm.length < 10 and sm.length > 0 do + cla.add_all(sm) + sm2.clear + for x in sm do + sm2.add_all(pe.poset[x].direct_smallers) + end + var t = sm + sm = sm2 + sm2 = t + end + cla.add_all(pe.greaters) + + var op = new Buffer + var name = "dep_{mclass.name}" + op.append("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n") + for c in cla do + if c == mclass then + op.append("\"{c.name}\"[shape=box,margin=0.03];\n") + else + op.append("\"{c.name}\"[URL=\"{c.name}.html\"];\n") + end + for c2 in pe.poset[c].direct_greaters do + if not cla.has(c2) then continue + op.append("\"{c.name}\"->\"{c2.name}\";\n") + end + if not pe.poset[c].direct_smallers.is_empty then + var others = true + for c2 in pe.poset[c].direct_smallers do + if cla.has(c2) then others = false + end + if others then + op.append("\"{c.name}...\"[label=\"\"];\n") + op.append("\"{c.name}...\"->\"{c.name}\"[style=dotted];\n") + end + end + end + op.append("\}\n") + generate_dot(op.to_s, name, "Dependency graph for class {mclass.name}") + end end redef class AModule private fun comment: String do - var ret = "" + var ret = new Buffer if n_moduledecl is null or n_moduledecl.n_doc is null then ret if n_moduledecl.n_doc is null then return "" for t in n_moduledecl.n_doc.n_comment do - ret += "{t.text.replace("# ", "")}" + ret.append(t.text.substring_from(1)) end - return ret + return ret.to_s.html_escape end private fun short_comment: String do - var ret = "" + var ret = new Buffer if n_moduledecl != null and n_moduledecl.n_doc != null then - var txt = n_moduledecl.n_doc.n_comment.first.text - txt = txt.replace("# ", "") - txt = txt.replace("\n", "") - ret += txt + ret.append(n_moduledecl.n_doc.n_comment.first.text.substring_from(2).replace("\n", "")) + end + return ret.to_s.html_escape + end +end + +redef class MModule + super Comparable + redef type OTHER: MModule + redef fun <(other: OTHER): Bool do return self.name < other.name + + # Get the list of all methods in a module + fun imported_methods: Set[MMethod] do + var methods = new HashSet[MMethod] + for mclass in imported_mclasses do + for method in mclass.intro_methods do + methods.add(method) + end + end + return methods + end + + # Get the list aof all refined methods in a module + fun redef_methods: Set[MMethod] do + var methods = new HashSet[MMethod] + for mclass in redef_mclasses do + for method in mclass.intro_methods do + methods.add(method) + end + end + return methods + end + + # Return a link (html a tag) to the nitdoc module page + fun link(mbuilder: ModelBuilder): String do + return "{name}" + end + + # Return the module signature decorated with html + fun html_signature(mbuilder: ModelBuilder): String do + return "module {html_namespace(mbuilder)}" + end + + # Return the module namespace decorated with html + fun html_namespace(mbuilder: ModelBuilder): String do + var res = new Buffer + res.append("") + var mowner = public_owner + if mowner != null then + res.append(public_owner.html_namespace(mbuilder)) + res.append("::") + end + res.append(self.link(mbuilder)) + res.append("") + return res.to_s + end + + # Return the full comment of the module decorated with html + fun html_full_comment(mbuilder: ModelBuilder): String do + var res = new Buffer + res.append("
    ") + res.append("
    {mbuilder.mmodule2nmodule[self].comment}
    ") + res.append("") + res.append("Cancel") + res.append("Commit") + res.append("
    ")
    +		res.append("
    ") + return res.to_s + end +end +redef class MPropDef + super Comparable + redef type OTHER: MPropDef + redef fun <(other: OTHER): Bool do return self.mproperty.name < other.mproperty.name + + # Return a link (html a tag) to the nitdoc class page + fun link(nprop: APropdef): String do + return "{mproperty.name}" + end +end + +redef class MProperty + super Comparable + redef type OTHER: MProperty + redef fun <(other: OTHER): Bool do return self.name < other.name + + var is_redef: Bool + var apropdef: nullable APropdef + + redef init(intro_mclassdef: MClassDef, name: String, visibility: MVisibility) + do + super + is_redef = false + end + + fun local_class: MClass do + var classdef = self.intro_mclassdef + return classdef.mclass + end + + fun anchor: String do + return "PROP_{c_name}" + end + + # Escape name for html output + redef fun name do return super.html_escape +end + +redef class MClass + super Comparable + redef type OTHER: MClass + redef fun <(other: OTHER): Bool do return self.name < other.name + + # Add type parameters + fun html_signature: String do + if arity > 0 then + return "{name}[{intro.parameter_names.join(", ")}]" + else + return name + end + end + + # Return a link (html a tag) to the nitdoc class page + fun link(aclass: AStdClassdef): String do + return "{html_signature}" + end + + # Associate all MMethods to each MModule concerns + fun all_methods: HashMap[MModule, Set[MMethod]] do + var hm = new HashMap[MModule, Set[MMethod]] + for mmodule, childs in concerns do + if not hm.has_key(mmodule) then hm[mmodule] = new HashSet[MMethod] + for prop in intro_methods do + if mmodule == prop.intro_mclassdef.mmodule then + prop.is_redef = false + hm[mmodule].add(prop) + end + end + for prop in redef_methods do + if mmodule == prop.intro_mclassdef.mmodule then + prop.is_redef = true + hm[mmodule].add(prop) + end + end + + if childs != null then + for child in childs do + if not hm.has_key(child) then hm[child] = new HashSet[MMethod] + for prop in intro_methods do + if child == prop.intro_mclassdef.mmodule then + prop.is_redef = false + hm[child].add(prop) + end + end + for prop in redef_methods do + if child == prop.intro_mclassdef.mmodule then + prop.is_redef = true + hm[child].add(prop) + end + end + end + end + end + return hm + end + + fun public_owner: MModule do + var owner = intro_mmodule + if owner.public_owner is null then + return owner + else + return owner.public_owner.as(not null) + end + end + + # Associate MClass to all MMethod include in 'inherited_methods' + fun inherited: HashMap[MClass, Set[MMethod]] do + var hm = new HashMap[MClass, Set[MMethod]] + for method in inherited_methods do + var mclass = method.intro_mclassdef.mclass + if not hm.has_key(mclass) then hm[mclass] = new HashSet[MMethod] + hm[mclass].add(method) + end + return hm + end + + # Return true if MModule concern contain subMModule + fun has_mmodule(sub: MModule): Bool do + for mmodule, childs in concerns do + if childs is null then continue + if childs.has(sub) then return true end + return false + end + + fun mmethod(mprop2npropdef: Map[MProperty, APropdef]) do + for const in constructors do + if mprop2npropdef.has_key(const)then + const.apropdef = mprop2npropdef[const].as(AMethPropdef) + end + end + + for intro in intro_methods do + if mprop2npropdef.has_key(intro)then + if mprop2npropdef[intro] isa AMethPropdef then intro.apropdef = mprop2npropdef[intro].as(AMethPropdef) + end + end + + for rd in redef_methods do + if mprop2npropdef.has_key(rd)then + if mprop2npropdef[rd] isa AMethPropdef then rd.apropdef = mprop2npropdef[rd].as(AMethPropdef) + end + end + end + + fun link_anchor: String do + return "{name}.html" + end + + # Escape name for html output + redef fun name do return super.html_escape +end + +redef class AStdClassdef + private fun comment: String do + var ret = new Buffer + if n_doc != null then + for t in n_doc.n_comment do ret.append(t.text.substring_from(1)) + end + return ret.to_s.html_escape + end + + private fun short_comment: String do + var ret = new Buffer + if n_doc != null then ret.append(n_doc.n_comment.first.text.substring_from(2).replace("\n", "")) + return ret.to_s.html_escape + end +end + +redef class ASignature + redef fun to_s do + #TODO closures + var ret = "" + if not n_params.is_empty then + ret = "{ret}({n_params.join(", ")})" + end + if n_type != null and n_type.to_s != "" then ret += ": {n_type.to_s}" return ret end end +redef class AParam + redef fun to_s do + var ret = "{n_id.text}" + if n_type != null then + ret = "{ret}: {n_type.to_s}" + if n_dotdotdot != null then ret = "{ret}..." + end + return ret + end +end + +redef class AType + redef fun to_s do + var ret = "{n_id.text}" + if n_kwnullable != null then ret = "nullable {ret}" + if not n_types.is_empty then ret = "{ret}[{n_types.join(", ")}]" + return ret + end +end + +redef class APropdef + private fun short_comment: String is abstract + private fun signature: String is abstract + private fun comment: String is abstract +end + +redef class AAttrPropdef + redef fun short_comment do + var ret = new Buffer + if n_doc != null then ret.append(n_doc.n_comment.first.text.substring_from(1)) + return ret.to_s.html_escape + end +end + +redef class AMethPropdef + redef fun short_comment do + var ret = new Buffer + if n_doc != null then ret.append(n_doc.n_comment.first.text.substring_from(2).replace("\n", "")) + return ret.to_s.html_escape + end + + redef fun signature: String do + var sign = "" + if n_signature != null then sign = "{n_signature.to_s}" + return sign + end + + redef private fun comment: String do + var ret = new Buffer + if n_doc != null then + for t in n_doc.n_comment do ret.append(t.text.substring_from(1)) + end + return ret.to_s.html_escape + end +end + +redef class MClassDef + private fun namespace(mclass: MClass): String do + + if mmodule.public_owner is null then + return "{mmodule.full_name}::{mclass.name}" + else if mclass is self.mclass then + return "{mmodule.public_owner.name}::{mclass.name}" + else + return "{mmodule.public_owner.name}::{mclass.name}" + end + end +end + +redef class Set[E] + fun last: E do + return to_a[length-1] + end +end + # Create a tool context to handle options and paths var toolcontext = new ToolContext -toolcontext.process_options # Here we launch the nit index var nitdoc = new Nitdoc(toolcontext)