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 mainmodule
.tpl_module
(self)
44 # Builds a dot UML package diagram entity from `self`
45 fun tpl_module
(model
: UMLModel): Writable is abstract
49 redef fun tpl_module
(model
) do
50 var name
= self.name
.escape_to_dot
52 t
.add
"subgraph cluster{name} \{\n"
53 t
.add
"label = \"{name}\
"\n"
54 for i
in mclassdefs
do
55 if not model
.view
.accept_mentity
(i
) then continue
56 t
.add i
.tpl_module
(model
)
65 # Colour for the border of a class when first introduced
67 # Defaults to a shade of green
68 var intro_colour
= "#58B26A"
70 # Colour for the border of a class when refined
72 # Defaults to a shade of red
73 var redef_colour
= "#B24758"
75 redef fun tpl_module
(model
) do
76 var name
= self.name
.escape_to_dot
78 t
.add
"{mmodule.name.escape_to_dot}{name} [\n\tlabel = \"\
{"
79 if mclass.kind == abstract_kind then
80 t.add "abstract\\n
{name}"
81 else if mclass.kind == interface_kind then
82 t.add "interface\\n
{name}"
86 if mclass.arity > 0 then
88 var mparameters = mclass.mparameters
89 t.add mparameters.first.name
90 for i in [1 .. mparameters.length[ do
92 t.add mparameters[i].name
98 if not i isa MAttributeDef then continue
99 if not model.view.accept_mentity(i) then continue
100 t.add i.tpl_module(model)
104 for i in mpropdefs do
105 if not i isa MMethodDef then continue
106 if not model.view.accept_mentity(i) then continue
107 t.add i.tpl_module(model)
112 t
.add
"color=\"{intro_colour}\
""
114 t
.add
"color=\"{redef_colour}\
""
117 var supers
= in_hierarchy
.direct_greaters
119 if i
.mmodule
!= mmodule
then continue
120 t
.add
"{i.mmodule}{i.name} -> {mmodule}{name} [dir=back"
121 if i
.mclass
.kind
== interface_kind
then
122 t
.add
" arrowtail=open style=dashed"
124 t
.add
" arrowtail=empty"
132 redef class MMethodDef
133 redef fun tpl_module
(model
) do
135 t
.add mproperty
.visibility
.tpl_class
137 t
.add name
.escape_to_dot
138 t
.add msignature
.tpl_class
(model
)
143 redef class MAttributeDef
144 redef fun tpl_module
(model
) do
146 t
.add mproperty
.visibility
.tpl_class
150 t
.add static_mtype
.tpl_class
(model
)