Skip to content

Instantly share code, notes, and snippets.

@chinying
Created October 21, 2016 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chinying/5c933ad6a11a3fc3aa771b7e302d3b23 to your computer and use it in GitHub Desktop.
Save chinying/5c933ad6a11a3fc3aa771b7e302d3b23 to your computer and use it in GitHub Desktop.
because i hate using java IDEs for web, so here's something for when using sublime. largely WIP
from collections import defaultdict
filepath = ""
classname = ""
fo = open(filepath)
contents = fo.read().split("\n")
def find_constructors(contents):
contd = False # continue looking
tmp_constructor = ""
constructors, idxs = [], []
for idx, l in enumerate(contents, start=1):
if contd == True:
tmp_constructor += l
if "{" in l:
contd = False
constructors.append(tmp_constructor)
tmp_constructor = ""
if ("public " + classname) in l:
idxs.append(idx)
tmp_constructor += l
if "{" not in l:
contd = True
else:
constructors.append(tmp_constructor)
tmp_constructor = ""
return list(zip(idxs, [a.strip()[:-1] for a in constructors]))
def signature(constructor):
idx = constructor.strip().replace('\\t', '').find('(')
var = (constructor[idx:]).split(",") # what if len(var) == 1
var[0] = var[0][1:]
if (len(var) > 1):
var[:-1] = var[:-1][:-1]
v = [x.strip().split() for x in var]
print (v)
ans = find_constructors(contents)
# print(ans[2])
print(signature(ans[2][1]))
# print(ans[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment