brackets.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #
  2. # Metrix++, Copyright 2009-2013, Metrix++ Project
  3. # Link: http://swi.sourceforge.net
  4. #
  5. # This file is a part of Metrix++ Tool.
  6. #
  7. # Metrix++ is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, version 3 of the License.
  10. #
  11. # Metrix++ is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Metrix++. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import core.api
  20. class Plugin(core.api.Plugin, core.api.Child, core.api.IConfigurable):
  21. def declare_configuration(self, parser):
  22. parser.add_option("--std.code.brackets.on", action="store_true", default=False,
  23. help="If enabled, counts number of mismatched brackets '{}' [default: %default]")
  24. def configure(self, options):
  25. self.is_active = options.__dict__['std.code.brackets.on']
  26. def initialize(self):
  27. if self.is_active == True:
  28. namespace = self.get_plugin_loader().get_database_loader().create_namespace(self.get_name())
  29. namespace.add_field('curly', int)
  30. core.api.subscribe_by_parents_name('std.code.cpp', self, 'callback_cpp')
  31. def callback_cpp(self, parent, data):
  32. if data.get_data(self.get_name(), 'curly') != None:
  33. return # data is available from cloned database, skip collection
  34. data.set_data(self.get_name(), 'curly', data.get_data(parent.get_name(), 'mismatched_brackets'))