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
module method_analyze_metrics
# We usualy need specific phases
# NOTE: `frontend` is sufficent in most case (it is often too much)
import nitsmell_toolcontext
import mclassdef_collect
fun call_analyze_methods(mclassdef: MClassDef, model_builder: ModelBuilder, filter: ModelFilter): Array[MMethodDef] do
var mmethoddefs = new Array[MMethodDef]
for m_prop in mclassdef.collect_intro_and_redef_mpropdefs(filter) do
var n_prop = model_builder.mpropdef2node(m_prop)
#Check if the property is a method definition
if n_prop isa AMethPropdef and m_prop isa MMethodDef then
if n_prop.n_methid isa AIdMethid then
#Call visitor to analyse the method
var visitor = new MethodAnalyzeMetrics(n_prop)
visitor.enter_visit(n_prop)
mmethoddefs.add(set_analyse_result_methoddef(m_prop,visitor))
end
end
end
return mmethoddefs
end
fun set_analyse_result_methoddef(mmethoddef: MMethodDef, visitor: MethodAnalyzeMetrics): MMethodDef do
mmethoddef.line_number = visitor.line_number.length
mmethoddef.total_self_call = visitor.total_self_call
mmethoddef.class_call = visitor.class_call
return mmethoddef
end
public class MethodAnalyzeMetrics
super Visitor
var ameth_prop_def: AMethPropdef
var line_number = new Counter[nullable Int]
var total_self_call = 0
var class_call = new Counter[MClassType]
redef fun visit(n) do
n.visit_all(self)
if n isa AExpr then
if not n isa ABlockExpr then
if n.first_location != null then
line_number.inc(n.first_location.line_start)
end
end
end
if n isa ASendExpr then
var callsite = n.callsite
if callsite != null then
var class_site_recv = callsite.recv
if class_site_recv isa MClassType then class_call.inc(class_site_recv)
if callsite.recv_is_self then self.total_self_call += 1
end
end
end
end
redef class MMethodDef
var line_number = 0
var total_self_call = 0
var class_call = new Counter[MClassType]
end
src/metrics/method_analyze_metrics.nit:16,1--79,3