# This file is part of NIT ( http://www.nitlanguage.org ). # # Copyright 2012 Jean Privat # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Dump of Nit model into hypertext human-readable format. module model_hyperdoc import metrics_base redef class ToolContext var model_hyperdoc_phase: Phase = new ModelHyperdocPhase(self, null) end private class ModelHyperdocPhase super Phase redef fun process_mainmodule(mainmodule, given_mmodules) do if not toolcontext.opt_generate_hyperdoc.value and not toolcontext.opt_all.value then return generate_model_hyperdoc(toolcontext, toolcontext.modelbuilder.model) end end # Genetate a HTML file for the model. # The generated file contains the description of each entity of the model fun generate_model_hyperdoc(toolcontext: ToolContext, model: Model) do var buf = new FlatBuffer buf.append("\n\n") buf.append("

Model

\n") buf.append("

Projects

\n") for mproject in model.mprojects do buf.append("

Project {mproject}

\n") buf.append("
\n") buf.append("
groups
\n") for x in mproject.mgroups do buf.append("
{linkto(x)}
\n") end buf.append("
\n") end buf.append("

Groups

\n") for mproject in model.mprojects do for mgroup in mproject.mgroups do buf.append("

Group {mgroup}

\n") buf.append("
\n") buf.append("
project
\n") buf.append("
{linkto(mproject)}
\n") buf.append("
filepath
\n") buf.append("
{mgroup.filepath.to_s}
\n") var p = mgroup.parent if p != null then buf.append("
parent group
\n") buf.append("
{linkto(p)}
\n") end buf.append("
nested groups
\n") for x in mgroup.in_nesting.direct_smallers do buf.append("
{linkto(x)}
\n") end buf.append("
modules
\n") for x in mgroup.mmodules do buf.append("
{linkto(x)}
\n") end end buf.append("
\n") end buf.append("

Modules

\n") for mmodule in model.mmodules do buf.append("

{mmodule}

\n") buf.append("
\n") buf.append("
group
\n") var grp = mmodule.mgroup if grp != null then buf.append("
{linkto(grp)}
\n") buf.append("
direct import
\n") for x in mmodule.in_importation.direct_greaters do buf.append("
{linkto(x)}
\n") end buf.append("
direct clients
\n") for x in mmodule.in_importation.direct_smallers do buf.append("
{linkto(x)}
\n") end buf.append("
introduced classes
\n") for x in mmodule.mclassdefs do if not x.is_intro then continue buf.append("
{linkto(x.mclass)} by {linkto(x)}
\n") end buf.append("
refined classes
\n") for x in mmodule.mclassdefs do if x.is_intro then continue buf.append("
{linkto(x.mclass)} by {linkto(x)}
\n") end buf.append("
\n") end buf.append("

Classes

\n") for mclass in model.mclasses do buf.append("

{mclass}

\n") buf.append("
\n") buf.append("
module of introduction
\n") buf.append("
{linkto(mclass.intro_mmodule)}
\n") buf.append("
class definitions
\n") for x in mclass.mclassdefs do buf.append("
{linkto(x)} in {linkto(x.mmodule)}
\n") end buf.append("
\n") end buf.append("

Class Definitions

\n") for mclass in model.mclasses do for mclassdef in mclass.mclassdefs do buf.append("

{mclassdef}

\n") buf.append("
\n") buf.append("
module
\n") buf.append("
{linkto(mclassdef.mmodule)}
\n") buf.append("
class
\n") buf.append("
{linkto(mclassdef.mclass)}
\n") buf.append("
direct refinements
\n") for x in mclassdef.in_hierarchy.direct_greaters do if x.mclass != mclass then continue buf.append("
{linkto(x)} in {linkto(x.mmodule)}
\n") end buf.append("
direct refinemees
\n") for x in mclassdef.in_hierarchy.direct_smallers do if x.mclass != mclass then continue buf.append("
{linkto(x)} in {linkto(x.mmodule)}
\n") end buf.append("
direct superclasses
\n") for x in mclassdef.supertypes do buf.append("
{linkto(x.mclass)} by {x}
\n") end buf.append("
introduced properties
\n") for x in mclassdef.mpropdefs do if not x.is_intro then continue buf.append("
{linkto(x.mproperty)} by {linkto(x)}
\n") end buf.append("
redefined properties
\n") for x in mclassdef.mpropdefs do if x.is_intro then continue buf.append("
{linkto(x.mproperty)} by {linkto(x)}
\n") end buf.append("
\n") end end buf.append("

Properties

\n") for mprop in model.mproperties do buf.append("

{mprop}

\n") buf.append("
\n") buf.append("
module of introdcution
\n") buf.append("
{linkto(mprop.intro_mclassdef.mmodule)}
\n") buf.append("
class of introduction
\n") buf.append("
{linkto(mprop.intro_mclassdef.mclass)}
\n") buf.append("
class definition of introduction
\n") buf.append("
{linkto(mprop.intro_mclassdef)}
\n") buf.append("
property definitions
\n") for x in mprop.mpropdefs do buf.append("
{linkto(x)} in {linkto(x.mclassdef)}
\n") end buf.append("
\n") end buf.append("

Property Definitions

\n") for mprop in model.mproperties do for mpropdef in mprop.mpropdefs do buf.append("

{mpropdef}

\n") buf.append("
\n") buf.append("
module
\n") buf.append("
{linkto(mpropdef.mclassdef.mmodule)}
\n") buf.append("
class
\n") buf.append("
{linkto(mpropdef.mclassdef.mclass)}
\n") buf.append("
class definition
\n") buf.append("
{linkto(mpropdef.mclassdef)}
\n") buf.append("
super definitions
\n") for x in mpropdef.mproperty.lookup_super_definitions(mpropdef.mclassdef.mmodule, mpropdef.mclassdef.bound_mtype) do buf.append("
{linkto(x)} in {linkto(x.mclassdef)}
\n") end end end buf.append("\n") var f = new FileWriter.open(toolcontext.output_dir.join_path("model.html")) f.write(buf.to_s) f.close end private fun linkto(o: Object): String do if o isa MProject then return "{o}" else if o isa MGroup then return "{o}" else if o isa MModule then return "{o}" else if o isa MClass then return "{o}" else if o isa MClassDef then return "{o}" else if o isa MProperty then return "{o}" else if o isa MPropDef then return "{o}" else print "cannot linkto {o.class_name}" abort end end