metrics: rta shows live classes and methods. hide customized_methoddefs
[nit.git] / src / metrics / model_hyperdoc.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2012 Jean Privat <jean@pryen.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Dump of Nit model into hypertext human-readable format.
18 module model_hyperdoc
19
20 import model
21 import metrics_base
22 import phase
23 import frontend
24
25 redef class ToolContext
26 var model_hyperdoc_phase = new ModelHyperdocPhase(self, null)
27 end
28
29 private class ModelHyperdocPhase
30 super Phase
31 redef fun process_mainmodule(mainmodule)
32 do
33 if not toolcontext.opt_generate_hyperdoc.value and not toolcontext.opt_all.value then return
34 generate_model_hyperdoc(toolcontext, toolcontext.modelbuilder.model)
35 end
36 end
37
38 # Genetate a HTML file for the model.
39 # The generated file contains the description of each entity of the model
40 fun generate_model_hyperdoc(toolcontext: ToolContext, model: Model)
41 do
42 var buf = new Buffer
43 buf.append("<html>\n<body>\n")
44 buf.append("<h1>Model</h1>\n")
45
46 buf.append("<h2>Modules</h2>\n")
47 for mmodule in model.mmodules do
48 buf.append("<h3 id='module-{mmodule}'>{mmodule}</h3>\n")
49 buf.append("<dl>\n")
50 buf.append("<dt>direct owner</dt>\n")
51 var own = mmodule.direct_owner
52 if own != null then buf.append("<dd>{linkto(own)}</dd>\n")
53 buf.append("<dt>nested</dt>\n")
54 for x in mmodule.in_nesting.direct_greaters do
55 buf.append("<dd>{linkto(x)}</dd>\n")
56 end
57 buf.append("<dt>direct import</dt>\n")
58 for x in mmodule.in_importation.direct_greaters do
59 buf.append("<dd>{linkto(x)}</dd>\n")
60 end
61 buf.append("<dt>direct clients</dt>\n")
62 for x in mmodule.in_importation.direct_smallers do
63 buf.append("<dd>{linkto(x)}</dd>\n")
64 end
65 buf.append("<dt>introduced classes</dt>\n")
66 for x in mmodule.mclassdefs do
67 if not x.is_intro then continue
68 buf.append("<dd>{linkto(x.mclass)} by {linkto(x)}</dd>\n")
69 end
70 buf.append("<dt>refined classes</dt>\n")
71 for x in mmodule.mclassdefs do
72 if x.is_intro then continue
73 buf.append("<dd>{linkto(x.mclass)} by {linkto(x)}</dd>\n")
74 end
75 buf.append("</dl>\n")
76 end
77 buf.append("<h2>Classes</h2>\n")
78 for mclass in model.mclasses do
79 buf.append("<h3 id='class-{mclass}'>{mclass}</h3>\n")
80 buf.append("<dl>\n")
81 buf.append("<dt>module of introduction</dt>\n")
82 buf.append("<dd>{linkto(mclass.intro_mmodule)}</dd>\n")
83 buf.append("<dt>class definitions</dt>\n")
84 for x in mclass.mclassdefs do
85 buf.append("<dd>{linkto(x)} in {linkto(x.mmodule)}</dd>\n")
86 end
87 buf.append("</dl>\n")
88 end
89 buf.append("<h2>Class Definitions</h2>\n")
90 for mclass in model.mclasses do
91 for mclassdef in mclass.mclassdefs do
92 buf.append("<h3 id='classdef-{mclassdef}'>{mclassdef}</h3>\n")
93 buf.append("<dl>\n")
94 buf.append("<dt>module</dt>\n")
95 buf.append("<dd>{linkto(mclassdef.mmodule)}</dd>\n")
96 buf.append("<dt>class</dt>\n")
97 buf.append("<dd>{linkto(mclassdef.mclass)}</dd>\n")
98 buf.append("<dt>direct refinements</dt>\n")
99 for x in mclassdef.in_hierarchy.direct_greaters do
100 if x.mclass != mclass then continue
101 buf.append("<dd>{linkto(x)} in {linkto(x.mmodule)}</dd>\n")
102 end
103 buf.append("<dt>direct refinemees</dt>\n")
104 for x in mclassdef.in_hierarchy.direct_smallers do
105 if x.mclass != mclass then continue
106 buf.append("<dd>{linkto(x)} in {linkto(x.mmodule)}</dd>\n")
107 end
108 buf.append("<dt>direct superclasses</dt>\n")
109 for x in mclassdef.supertypes do
110 buf.append("<dd>{linkto(x.mclass)} by {x}</dd>\n")
111 end
112 buf.append("<dt>introduced properties</dt>\n")
113 for x in mclassdef.mpropdefs do
114 if not x.is_intro then continue
115 buf.append("<dd>{linkto(x.mproperty)} by {linkto(x)}</dd>\n")
116 end
117 buf.append("<dt>redefined properties</dt>\n")
118 for x in mclassdef.mpropdefs do
119 if x.is_intro then continue
120 buf.append("<dd>{linkto(x.mproperty)} by {linkto(x)}</dd>\n")
121 end
122 buf.append("</dl>\n")
123 end
124 end
125 buf.append("<h2>Properties</h2>\n")
126 for mprop in model.mproperties do
127 buf.append("<h3 id='property-{mprop}'>{mprop}</h3>\n")
128 buf.append("<dl>\n")
129 buf.append("<dt>module of introdcution</dt>\n")
130 buf.append("<dd>{linkto(mprop.intro_mclassdef.mmodule)}</dd>\n")
131 buf.append("<dt>class of introduction</dt>\n")
132 buf.append("<dd>{linkto(mprop.intro_mclassdef.mclass)}</dd>\n")
133 buf.append("<dt>class definition of introduction</dt>\n")
134 buf.append("<dd>{linkto(mprop.intro_mclassdef)}</dd>\n")
135 buf.append("<dt>property definitions</dt>\n")
136 for x in mprop.mpropdefs do
137 buf.append("<dd>{linkto(x)} in {linkto(x.mclassdef)}</dd>\n")
138 end
139 buf.append("</dl>\n")
140 end
141 buf.append("<h2>Property Definitions</h2>\n")
142 for mprop in model.mproperties do
143 for mpropdef in mprop.mpropdefs do
144 buf.append("<h3 id='propdef-{mpropdef}'>{mpropdef}</h3>\n")
145 buf.append("<dl>\n")
146 buf.append("<dt>module</dt>\n")
147 buf.append("<dd>{linkto(mpropdef.mclassdef.mmodule)}</dd>\n")
148 buf.append("<dt>class</dt>\n")
149 buf.append("<dd>{linkto(mpropdef.mclassdef.mclass)}</dd>\n")
150 buf.append("<dt>class definition</dt>\n")
151 buf.append("<dd>{linkto(mpropdef.mclassdef)}</dd>\n")
152 buf.append("<dt>super definitions</dt>\n")
153 for x in mpropdef.mproperty.lookup_super_definitions(mpropdef.mclassdef.mmodule, mpropdef.mclassdef.bound_mtype) do
154 buf.append("<dd>{linkto(x)} in {linkto(x.mclassdef)}</dd>\n")
155 end
156 end
157 end
158 buf.append("</body></html>\n")
159 var f = new OFStream.open(toolcontext.output_dir.join_path("model.html"))
160 f.write(buf.to_s)
161 f.close
162 end
163
164 private fun linkto(o: Object): String
165 do
166 if o isa MModule then
167 return "<a href='#module-{o}'>{o}</a>"
168 else if o isa MClass then
169 return "<a href='#class-{o}'>{o}</a>"
170 else if o isa MClassDef then
171 return "<a href='#classdef-{o}'>{o}</a>"
172 else if o isa MProperty then
173 return "<a href='#property-{o}'>{o}</a>"
174 else if o isa MPropDef then
175 return "<a href='#propdef-{o}'>{o}</a>"
176 else
177 print "cannot linkto {o.class_name}"
178 abort
179 end
180 end