Skip to content

Instantly share code, notes, and snippets.

@afeinberg
Created September 1, 2011 02:20
Show Gist options
  • Save afeinberg/1185286 to your computer and use it in GitHub Desktop.
Save afeinberg/1185286 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys, re
GETTER_REGEX = 'public (String|long|int|double) (get[^\(]+)'
LEADING_SPACES = ' '
def jmxify(file_name):
"""Add JMX getter annotations to all public methods"""
infile = open(file_name, 'r')
try:
for line in infile:
str_stripped = line.lstrip()
m = re.search(GETTER_REGEX, str_stripped)
if m != None:
name = m.group(2).replace('get', '')
sys.stdout.write(LEADING_SPACES + '@JmxGetter(name = "' + name + '")\n')
sys.stdout.write(line)
finally:
infile.close()
if __name__ == '__main__':
file_name = sys.argv[1]
jmxify(file_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment