1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Services for generation of a UML package diagram based on a `Model`
22 # Generates a UML package diagram from a `Model`
23 fun generate_package_uml
: Writable do
24 var tpl
= new Template
25 tpl
.add
"digraph G \{\n"
26 tpl
.add
""" fontname = "Bitstream Vera Sans"
29 fontname = "Bitstream Vera Sans"
34 fontname = "Bitstream Vera Sans"
37 tpl
.add model
.tpl_module
(ctx
, mainmodule
)
44 # Returns a UML package diagram of `main`
45 fun tpl_module
(ctx
: ToolContext, main
: MModule): Writable do
46 return main
.tpl_module
(ctx
, main
)
51 redef fun tpl_module
(ctx
, main
) do
53 t
.add
"subgraph cluster{name} \{\n"
54 t
.add
"label = \"{name}\
"\n"
55 for i
in mclassdefs
do
56 if not ctx
.private_gen
and i
.mclass
.visibility
!= public_visibility
then continue
57 t
.add i
.tpl_module
(ctx
, main
)
65 # Builds a dot UML package diagram entity from `self`
66 fun tpl_module
(ctx
: ToolContext, main
: MModule): Writable is abstract
71 # Colour for the border of a class when first introduced
73 # Defaults to a shade of green
74 var intro_colour
= "#58B26A"
76 # Colour for the border of a class when refined
78 # Defaults to a shade of red
79 var redef_colour
= "#B24758"
81 redef fun tpl_module
(ctx
, main
) do
83 t
.add
"{mmodule}{name} [\n\tlabel = \"\
{"
84 if mclass.kind == abstract_kind then
85 t.add "abstract\\n
{name}"
86 else if mclass.kind == interface_kind then
87 t.add "interface\\n
{name}"
91 if mclass.arity > 0 then
93 var mparameters = mclass.mparameters
94 t.add mparameters.first.name
95 for i in [1 .. mparameters.length[ do
97 t.add mparameters[i].name
102 for i in mpropdefs do
103 if not i isa MAttributeDef then continue
104 if not ctx.private_gen and i.mproperty.visibility != public_visibility then continue
105 t.add i.tpl_module(ctx, main)
109 for i in mpropdefs do
110 if not i isa MMethodDef then continue
111 if not ctx.private_gen and i.mproperty.visibility != public_visibility then continue
112 t.add i.tpl_module(ctx, main)
117 t
.add
"color=\"{intro_colour}\
""
119 t
.add
"color=\"{redef_colour}\
""
122 var supers
= in_hierarchy
.direct_greaters
124 if i
.mmodule
!= mmodule
then continue
125 t
.add
"{i.mmodule}{i.name} -> {mmodule}{name} [dir=back"
126 if i
.mclass
.kind
== interface_kind
then
127 t
.add
" arrowtail=open style=dashed"
129 t
.add
" arrowtail=empty"
137 redef class MMethodDef
138 redef fun tpl_module
(ctx
, main
) do
140 t
.add mproperty
.visibility
.tpl_class
142 t
.add name
.escape_to_dot
143 t
.add msignature
.tpl_class
(ctx
, main
)
148 redef class MAttributeDef
149 redef fun tpl_module
(ctx
, main
) do
151 t
.add mproperty
.visibility
.tpl_class
155 t
.add static_mtype
.tpl_class
(ctx
, main
)