nitmetrics: refactor self usage metrics computation
authorAlexandre Terrasa <alexadre@moz-code.org>
Sun, 4 Nov 2012 20:30:34 +0000 (15:30 -0500)
committerJean Privat <jean@pryen.org>
Mon, 5 Nov 2012 19:17:53 +0000 (14:17 -0500)
Signed-off-by: Alexandre Terrasa <alexadre@moz-code.org>

src/metrics/metrics.nit
src/metrics/metrics_base.nit
src/metrics/self_metrics.nit [moved from src/metrics/visit_self.nit with 87% similarity]
src/nitmetrics.nit

index 98f4567..fef9566 100644 (file)
@@ -20,7 +20,7 @@ module metrics
 import metrics_base
 import static_types_metrics
 import nullables_metrics
-import visit_self
+import self_metrics
 import model_stats
 import generate_hierarchies
 import rta_metrics
index 37a56be..56641ec 100644 (file)
@@ -21,6 +21,8 @@ import modelbuilder
 
 redef class ToolContext
 
+       # --self
+       var opt_self = new OptionBool("Compute metrics about the usage of explicit and implicit self", "--self")
        # --nullables
        var opt_nullables = new OptionBool("Compute metrics on nullables send", "--nullables")
        # --static-types
@@ -38,6 +40,7 @@ redef class ToolContext
        redef init
        do
                super
+               self.option_context.add_option(opt_self)
                self.option_context.add_option(opt_nullables)
                self.option_context.add_option(opt_static_types)
                self.option_context.add_option(opt_tables)
similarity index 87%
rename from src/metrics/visit_self.nit
rename to src/metrics/self_metrics.nit
index cc064e7..58aa69d 100644 (file)
@@ -14,8 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Statistics about the usage of explicit and implicit self
-module visit_self
+# Metrics about the usage of explicit and implicit self
+module self_metrics
 
 import modelbuilder
 private import metrics_base
@@ -37,8 +37,8 @@ private class ASelfVisitor
        end
 end
 
-# Visit the AST and print statistics about the usage of self.
-fun visit_self(modelbuilder: ModelBuilder)
+# 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
index caa0584..5d93ceb 100644 (file)
@@ -59,8 +59,11 @@ print "*** STATS ***"
 print ""
 compute_statistics(model)
 
-print ""
-visit_self(modelbuilder)
+# Self usage metrics
+if toolcontext.opt_self.value then
+       print ""
+       compute_self_metrics(modelbuilder)
+end
 
 # Nullables metrics
 if toolcontext.opt_nullables.value then