|
@@ -0,0 +1,50 @@
|
|
|
+#
|
|
|
+# Metrix++, Copyright 2009-2019, Metrix++ Project
|
|
|
+# Link: https://github.com/metrixplusplus/metrixplusplus
|
|
|
+#
|
|
|
+# This file is a part of Metrix++ Tool.
|
|
|
+#
|
|
|
+
|
|
|
+import mpp.api
|
|
|
+
|
|
|
+class Plugin(mpp.api.Plugin,
|
|
|
+ mpp.api.IConfigurable,
|
|
|
+ mpp.api.Child,
|
|
|
+ mpp.api.MetricPluginMixin):
|
|
|
+
|
|
|
+ def declare_configuration(self, parser):
|
|
|
+ self.parser = parser
|
|
|
+ parser.add_option("--std.code.ratio.commentcode", "--scrcc", action="store_true", default=False,
|
|
|
+ help="Enables collection of comment ratio metric (per region detalization) - "
|
|
|
+ "ratio of non-empty lines of comments to non-empty lines of code"
|
|
|
+ " It uses std.code.lines.code, std.code.lines.comments"
|
|
|
+ " metrics to calculate the ratio."
|
|
|
+ " [default: %default]")
|
|
|
+
|
|
|
+ def configure(self, options):
|
|
|
+ self.is_active_ratiocommentcode = options.__dict__['std.code.ratio.commentcode']
|
|
|
+ if self.is_active_ratiocommentcode == True:
|
|
|
+ required_opts = ['std.code.lines.comments', 'std.code.lines.code']
|
|
|
+ for each in required_opts:
|
|
|
+ if options.__dict__[each] == False:
|
|
|
+ self.parser.error('option --std.code.ratio.commentcode: requires --{0} option'.
|
|
|
+ format(each))
|
|
|
+
|
|
|
+ def initialize(self):
|
|
|
+ self.declare_metric(self.is_active_ratiocommentcode,
|
|
|
+ self.Field('commentcode', float),
|
|
|
+ {
|
|
|
+ 'std.code.lines':(None, self.RatioCalculatorCounter)
|
|
|
+ },
|
|
|
+ # set none, because this plugin is not interested in parsing the code
|
|
|
+ marker_type_mask=mpp.api.Marker.T.NONE)
|
|
|
+
|
|
|
+ super(Plugin, self).initialize(fields=self.get_fields())
|
|
|
+
|
|
|
+ if self.is_active() == True:
|
|
|
+ self.subscribe_by_parents_name('std.code.lines')
|
|
|
+
|
|
|
+ class RatioCalculatorCounter(mpp.api.MetricPluginMixin.RatioCalculator):
|
|
|
+ ratio_dividend = ('std.code.lines', 'comments')
|
|
|
+ ratio_divisor = ('std.code.lines', 'code')
|
|
|
+
|