X-Git-Url: http://nitlanguage.org diff --git a/src/metrics/inheritance_metrics.nit b/src/metrics/inheritance_metrics.nit index 8c799ac..7638758 100644 --- a/src/metrics/inheritance_metrics.nit +++ b/src/metrics/inheritance_metrics.nit @@ -17,22 +17,23 @@ # Collect metrics about inheritance usage module inheritance_metrics -import model +import metrics_base import mmodules_metrics import mclasses_metrics -import phase -import frontend redef class ToolContext - var inheritance_metrics_phase = new InheritanceMetricsPhase(self, null) + var inheritance_metrics_phase: Phase = new InheritanceMetricsPhase(self, null) end # Extract metrics about inheritance from model. private class InheritanceMetricsPhase super Phase - redef fun process_mainmodule(mainmodule) + redef fun process_mainmodule(mainmodule, given_mmodules) do if not toolcontext.opt_inheritance.value and not toolcontext.opt_all.value then return + var csv = toolcontext.opt_csv.value + var out = "{toolcontext.opt_dir.value or else "metrics"}/inheritance" + out.mkdir print toolcontext.format_h1("\n# Inheritance metrics") @@ -58,11 +59,11 @@ private class InheritanceMetricsPhase var model = toolcontext.modelbuilder.model var mmodules = new HashSet[MModule] var mclasses = new HashSet[MClass] - for mproject in model.mprojects do + for mpackage in model.mpackages do - print toolcontext.format_h2("\n ## project {mproject}") + print toolcontext.format_h2("\n ## package {mpackage}") - for mgroup in mproject.mgroups do + for mgroup in mpackage.mgroups do if mgroup.mmodules.is_empty then continue # Scalar metrics @@ -73,28 +74,14 @@ private class InheritanceMetricsPhase if mod_mclasses.is_empty then continue mmodules.add_all(mgroup.mmodules) mclasses.add_all(mod_mclasses) + cmetrics.clear cmetrics.collect(new HashSet[MClass].from(mod_mclasses)) - for metric in cmetrics.metrics do - if metric isa IntMetric then - print toolcontext.format_h4("\t{metric.name}: {metric.desc}") - print toolcontext.format_p("\t avg: {metric.avg}") - var max = metric.max - print toolcontext.format_p("\t max: {max.first} ({max.second})") - var min = metric.min - print toolcontext.format_p("\t min: {min.first} ({min.second})") - end - end + cmetrics.to_console(1, not toolcontext.opt_nocolors.value) + if csv then cmetrics.to_csv.write_to_file("{out}/{mgroup}_classes.csv") + hmetrics.clear hmetrics.collect(new HashSet[MModule].from(mgroup.mmodules)) - for metric in hmetrics.metrics do - if metric isa FloatMetric then - print toolcontext.format_h4("\t{metric.name}: {metric.desc}") - print toolcontext.format_p("\t avg: {metric.avg}") - var max = metric.max - print toolcontext.format_p("\t max: {max.first} ({max.second})") - var min = metric.min - print toolcontext.format_p("\t min: {min.first} ({min.second})") - end - end + hmetrics.to_console(1, not toolcontext.opt_nocolors.value) + if csv then hmetrics.to_csv.write_to_file("{out}/{mgroup}_inheritance.csv") end end if not mclasses.is_empty then @@ -102,28 +89,12 @@ private class InheritanceMetricsPhase print toolcontext.format_h2("\n ## global metrics") cmetrics.clear cmetrics.collect(mclasses) - for metric in cmetrics.metrics do - if metric isa IntMetric then - print toolcontext.format_h4("\t{metric.name}: {metric.desc}") - print toolcontext.format_p("\t avg: {metric.avg}") - var max = metric.max - print toolcontext.format_p("\t max: {max.first} ({max.second})") - var min = metric.min - print toolcontext.format_p("\t min: {min.first} ({min.second})") - end - end + cmetrics.to_console(1, not toolcontext.opt_nocolors.value) + if csv then cmetrics.to_csv.write_to_file("{out}/summary_classes.csv") hmetrics.clear hmetrics.collect(mmodules) - for metric in hmetrics.metrics do - if metric isa FloatMetric then - print toolcontext.format_h4("\t{metric.name}: {metric.desc}") - print toolcontext.format_p("\t avg: {metric.avg}") - var max = metric.max - print toolcontext.format_p("\t max: {max.first} ({max.second})") - var min = metric.min - print toolcontext.format_p("\t min: {min.first} ({min.second})") - end - end + hmetrics.to_console(1, not toolcontext.opt_nocolors.value) + if csv then hmetrics.to_csv.write_to_file("{out}/summary_inheritance.csv") end end end