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
51 t
.add
"subgraph cluster{name} \{\n"
52 t
.add
"label = \"{name}\
"\n"
53 for i
in mclassdefs
do
54 if not model
.view
.accept_mentity
(i
) then continue
55 t
.add i
.tpl_module
(model
)
64 # Colour for the border of a class when first introduced
66 # Defaults to a shade of green
67 var intro_colour
= "#58B26A"
69 # Colour for the border of a class when refined
71 # Defaults to a shade of red
72 var redef_colour
= "#B24758"
74 redef fun tpl_module
(model
) do
76 t
.add
"{mmodule}{name} [\n\tlabel = \"\
{"
77 if mclass.kind == abstract_kind then
78 t.add "abstract\\n
{name}"
79 else if mclass.kind == interface_kind then
80 t.add "interface\\n
{name}"
84 if mclass.arity > 0 then
86 var mparameters = mclass.mparameters
87 t.add mparameters.first.name
88 for i in [1 .. mparameters.length[ do
90 t.add mparameters[i].name
96 if not i isa MAttributeDef then continue
97 if not model.view.accept_mentity(i) then continue
98 t.add i.tpl_module(model)
102 for i in mpropdefs do
103 if not i isa MMethodDef then continue
104 if not model.view.accept_mentity(i) then continue
105 t.add i.tpl_module(model)
110 t
.add
"color=\"{intro_colour}\
""
112 t
.add
"color=\"{redef_colour}\
""
115 var supers
= in_hierarchy
.direct_greaters
117 if i
.mmodule
!= mmodule
then continue
118 t
.add
"{i.mmodule}{i.name} -> {mmodule}{name} [dir=back"
119 if i
.mclass
.kind
== interface_kind
then
120 t
.add
" arrowtail=open style=dashed"
122 t
.add
" arrowtail=empty"
130 redef class MMethodDef
131 redef fun tpl_module
(model
) do
133 t
.add mproperty
.visibility
.tpl_class
135 t
.add name
.escape_to_dot
136 t
.add msignature
.tpl_class
(model
)
141 redef class MAttributeDef
142 redef fun tpl_module
(model
) do
144 t
.add mproperty
.visibility
.tpl_class
148 t
.add static_mtype
.tpl_class
(model
)