Merge: doc: fixed some typos and other misc. corrections
[nit.git] / src / nituml.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 # UML generator in dot format.
16 module nituml
17
18 import modelbuilder
19 import frontend
20 import uml
21
22 redef class ToolContext
23
24 # Phase that generates UML diagrams from model entities.
25 var umlphase: Phase = new UMLPhase(self, null)
26
27 # What to generate?
28 var opt_gen = new OptionEnum(["class", "package"], "Choose which type of uml diagram to generate", 0, "--diagram")
29
30 # Generate private?
31 var opt_privacy = new OptionBool("Generates private API", "-p", "--private")
32
33 redef init do
34 option_context.add_option opt_gen
35 option_context.add_option opt_privacy
36 super
37 end
38 end
39
40 private class UMLPhase
41 super Phase
42 redef fun process_mainmodule(mainmodule, mmodules)
43 do
44 var filters = new ModelFilter
45 if not toolcontext.opt_privacy.value then
46 filters.min_visibility = protected_visibility
47 end
48
49 var d = new UMLModel(toolcontext.modelbuilder.model, mainmodule, filters)
50 if toolcontext.opt_gen.value == 0 then
51 print d.generate_class_uml.write_to_string
52 else if toolcontext.opt_gen.value == 1 then
53 print d.generate_package_uml.write_to_string
54 end
55 end
56 end
57
58 # process options
59 var toolcontext = new ToolContext
60 toolcontext.process_options(args)
61 var arguments = toolcontext.option_context.rest
62
63 # build model
64 var model = new Model
65 var mbuilder = new ModelBuilder(model, toolcontext)
66 var mmodules = mbuilder.parse_full(arguments)
67
68 if mmodules.is_empty then return
69 mbuilder.run_phases
70 toolcontext.run_global_phases(mmodules)