def CallAstor(func_name): function = getattr(test_func,func_name) func_ast = astor.codetoast(function) # make sure to call this from the test directory # otherweise need to fix the path here filename = str(function.__name__ +'.java') f = open(filename, 'w') # activate to print AST again print(astor.dump(func_ast)) print>>f, astor.to_source(func_ast, function.__name__) return filename
def CallAstor(func_name): function = getattr(test_func, func_name) func_ast = astor.codetoast(function) # make sure to call this from the test directory # otherweise need to fix the path here filename = str(function.__name__ + '.java') f = open(filename, 'w') # activate to print AST again print(astor.dump(func_ast)) print >> f, astor.to_source(func_ast, function.__name__) return filename
#!/usr/bin/env python import sys import os sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import astor def TestMe(x, y, width=10, foo=None): from foo.bar.baz.murgatroyd import sally as bob a.b = c.d + x.y.z.a.b m.n = q = (w.w, x.x.y.y) = f(x.x.y.z) func_ast = astor.codetoast(TestMe) print(astor.dump(func_ast)) print(astor.to_source(func_ast)) class ConsolidateAttributes(astor.TreeWalk): def post_Attribute(self): node = self.cur_node value = node.value value.id += '.' + node.attr self.replace(value) ConsolidateAttributes(func_ast) class FindNames(astor.TreeWalk): def init_Assign(self): self.assignments = [] self.current_assign = None def pre_Assign(self):