nitc :: self_metrics
nitc :: ASelfVisitor
Serializable::inspect
to show more useful information
nitc :: modelbuilder
more_collections :: more_collections
Highly specific, but useful, collections-related classes.serialization :: serialization_core
Abstract services to serialize Nit objects to different formatsnitc :: toolcontext
Common command-line tool infrastructure than handle options and error messagescore :: union_find
union–find algorithm using an efficient disjoint-set data structurenitc :: api_metrics
nitc :: nitmetrics
A program that collects various metrics on nit programs and libraries
# Metrics about the usage of explicit and implicit self
module self_metrics
import metrics_base
redef class ToolContext
var self_metrics_phase: Phase = new SelfMetricsPhase(self, null)
end
private class SelfMetricsPhase
super Phase
redef fun process_mainmodule(mainmodule, given_mmodules)
do
if not toolcontext.opt_self.value and not toolcontext.opt_all.value then return
compute_self_metrics(toolcontext.modelbuilder)
end
end
private class ASelfVisitor
super Visitor
var total: Int = 0
var implicits: Int = 0
redef fun visit(n)
do
if n isa ASelfExpr then
self.total += 1
if n isa AImplicitSelfExpr then
self.implicits += 1
end
end
n.visit_all(self)
end
end
# Visit the AST and print metics about the usage of self.
fun compute_self_metrics(modelbuilder: ModelBuilder)
do
print "--- Explicit vs. Implicit Self ---"
# Visit all the source code to collect data
var visitor = new ASelfVisitor
for nmodule in modelbuilder.nmodules do
for nclassdef in nmodule.n_classdefs do
visitor.enter_visit(nclassdef)
end
end
print "Total number of self: {visitor.total}"
print "Total number of implicit self: {visitor.implicits} ({div(visitor.implicits*100,visitor.total)}%)"
end
src/metrics/self_metrics.nit:17,1--65,3