Rename REAMDE to README.md
[nit.git] / src / metrics / inheritance_metrics.nit
index 8c799ac..d475562 100644 (file)
 # 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")
 
@@ -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.save("{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.save("{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.save("{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.save("{out}/summary_inheritance.csv")
                end
        end
 end