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 # Example of model_visitor
16 module test_model_visitor
23 # Example visitor that just count kind of entities.
24 class TestModelVisitor
32 # Counter of visited entities (by classnames)
33 var cpt
= new Counter[String]
36 # The body of the specific work.
37 # The main entry point is provided by `test_phase`,
38 # This function is then automatically (unless errors where found).
39 redef fun do_work
(mainmodule
, given_mmodules
, modelbuilder
)
41 var model
= modelbuilder
.model
43 print
"All entities, including fictive ones:"
44 var v
= new TestModelVisitor
45 v
.min_visibility
= private_visibility
46 v
.include_fictive
= true
48 v
.cpt
.print_elements
(10)
51 v
= new TestModelVisitor
52 v
.min_visibility
= private_visibility
54 v
.cpt
.print_elements
(10)
56 print
"\nAll non-private entities:"
57 v
= new TestModelVisitor
58 v
.min_visibility
= protected_visibility
60 v
.cpt
.print_elements
(10)
62 print
"\nAll documented non-private entities:"
63 v
= new TestModelVisitor
64 v
.min_visibility
= protected_visibility
65 v
.include_empty_doc
= false
67 v
.cpt
.print_elements
(10)
69 print
"\nAll public entities:"
70 v
= new TestModelVisitor
71 v
.min_visibility
= public_visibility
73 v
.cpt
.print_elements
(10)
75 print
"\nAll documented public entities:"
76 v
= new TestModelVisitor
77 v
.min_visibility
= public_visibility
78 v
.include_empty_doc
= false
80 v
.cpt
.print_elements
(10)