Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This is a simple python script that can list all the methods in a file.
methodSignature = '(public|protected|private|static|\s) +[\w\<\>\[\]]+\s+(\w+) *\([^\)]*\) *(\{?|[^;])'
import traceback
def main():
import getopt, sys, re
options, args = getopt.getopt(sys.argv[1:], 'i:h', ['input=','help'])
except getopt.GetoptError as err:
# print help information and exit:
print(err) # will print something like 'option -a not recognized'
javaFile = ''
# read args
for opt, arg in options:
if opt in ('-i', '--input'):
javaFile = arg
if javaFile is '': javaFile = sys.argv[1]
with open(javaFile, "rU") as file:
lines = file.readlines()
print '//',javaFile
print '//',len(lines), 'lines of code'
methods = {}
for line in lines:
m =,line)
if len(>0 :
methodLine =
methodLine = methodLine.replace(' {','')
access, type, methodSig = methodLine.split(' ',2)
# print
methods[methodSig] = (access, type)
except: a=1
#print '\nSorted list\n'
for methodSig in sorted(methods.keys()):
(access,type) = methods[methodSig]
print '{} {} {};'.format(access,type,methodSig)
except Exception, e:
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment