nitc :: actors_injection_phase
Injects model for the classes annotated with "is actor" sonitc :: astbuilder
Instantiation and transformation of semantic nodes in the AST of expressions and statementsnitc :: i18n_phase
Basic support of internationalization through the generation of id-to-string tablesSerializable::inspect
to show more useful information
nitc :: modelbuilder
more_collections :: more_collections
Highly specific, but useful, collections-related classes.threaded
annotation
serialization :: serialization_core
Abstract services to serialize Nit objects to different formatsnitc :: serialization_model_phase
Phase generating methods (model-only) to serialize Nit objectsnitc :: toolcontext
Common command-line tool infrastructure than handle options and error messagescore :: union_find
union–find algorithm using an efficient disjoint-set data structure
# Example of model_visitor
module test_model_visitor
import test_phase
import frontend
import model_visitor
import counter
# Example visitor that just count kind of entities.
class TestModelVisitor
super ModelVisitor
redef fun visit(e) do
cpt.inc(e.class_name)
if not e isa Model then
var name = e.full_name
var old = names.get_or_null(name)
if old != null then
names[name + "!CONFLICT!" + old.class_name] = old
name = name + "!CONFLICT!" + e.class_name
end
names[name] = e
end
e.visit_all(self)
end
# Counter of visited entities (by classnames)
var cpt = new Counter[String]
# Dictionary of full_names
var names = new Map[String, MEntity]
end
# The body of the specific work.
# The main entry point is provided by `test_phase`,
# This function is then automatically (unless errors where found).
redef fun do_work(mainmodule, given_mmodules, modelbuilder)
do
var model = modelbuilder.model
print "All entities, including fictive ones:"
var filters = new ModelFilter(private_visibility, accept_fictive = true)
var v = new TestModelVisitor(filters)
v.enter_visit(model)
v.cpt.print_elements(10)
var names = v.names
print "All entities:"
filters = new ModelFilter(private_visibility)
v = new TestModelVisitor(filters)
v.enter_visit(model)
v.cpt.print_elements(10)
print "\nAll non-private entities:"
filters = new ModelFilter(protected_visibility)
v = new TestModelVisitor(filters)
v.enter_visit(model)
v.cpt.print_elements(10)
print "\nAll documented non-private entities:"
filters = new ModelFilter(protected_visibility, accept_empty_doc = false)
v = new TestModelVisitor(filters)
v.enter_visit(model)
v.cpt.print_elements(10)
print "\nAll public entities:"
filters = new ModelFilter(public_visibility)
v = new TestModelVisitor(filters)
v.enter_visit(model)
v.cpt.print_elements(10)
print "\nAll documented public entities:"
filters = new ModelFilter(public_visibility, accept_empty_doc = false)
v = new TestModelVisitor(filters)
v.enter_visit(model)
v.cpt.print_elements(10)
print "\nNames:"
print "\n# Classes of entities"
var cpt
cpt = new Counter[String]
for n, e in names do
cpt.inc(e.class_name)
end
cpt.print_summary
cpt.print_elements(10)
print "\n# Name length of entities"
cpt = new Counter[String]
for n, e in names do
cpt[n] = n.length
end
cpt.print_summary
cpt.print_elements(10)
print "\n# All entities"
for n, e in names do
var c = ""
var d = e.mdoc_or_fallback
if d != null and d.content.not_empty then c = d.content.first
print "{n}\t{e.class_name}\t{e.location}\t{c}"
end
end
src/test_model_visitor.nit:15,1--119,3