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
28 if not doc_only
or e
.mdoc
!= null then
34 # Counter of visited entities (by classnames)
35 var cpt
= new Counter[String]
37 # Do the visitor only count entities with a documentation?
41 # The body of the specific work.
42 # The main entry point is provided by `test_phase`,
43 # This function is then automatically (unless errors where found).
44 redef fun do_work
(mainmodule
, given_mmodules
, modelbuilder
)
46 var model
= modelbuilder
.model
48 print
"All entities, including fictive ones:"
49 var v
= new TestModelVisitor
50 v
.include_fictive
= true
52 v
.cpt
.print_elements
(10)
55 v
= new TestModelVisitor
57 v
.cpt
.print_elements
(10)
59 print
"\nAll non-private entities:"
60 v
= new TestModelVisitor
61 v
.min_visibility
= protected_visibility
63 v
.cpt
.print_elements
(10)
65 print
"\nAll documented non-private entities:"
66 v
= new TestModelVisitor
67 v
.min_visibility
= protected_visibility
70 v
.cpt
.print_elements
(10)