Build Java code using Python

Asked

Viewed 39 times

1

I want to create a python script that given a name of a JAVA function looks for it in a library and copies it to another file. Is there any way to search for JAVA functions (providing the name) without doing string-to-string search?

1 answer

0

String a string "Wont cut it" - you will have to create a minimalist parser - possibly even make a regular expression - that reads the file, find the method statements, start and end lines (for this, just count the balance of "{" and "}" - and cut out this part of the text.

I would read the whole file and make a mixed loop: taking at the same time a whole row (looking forward in the text to the next "{") to find class and method statements, and a character-by-character loop, keeping status information to count how many keys ("{") were opened and how many closed.

Within a class, on any line with zero open keys where you have a "(" and don’t have a "=" sign you are in the declaration of a method - that you can use the split method even to have the method name.

Depending on what else you need to do, you can try this approach, or search for "java parsers'in Python -- a quick search in Pypi returned this one: https://pypi.python.org/pypi/javalang/0.10.2 - see his documentation and if he already does what you need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.