Refactoring in gen_java.py script