def java2pythonlinebyline(txt):
    if txt.find('if (') >= 0:
        if not txt.strip().endswith("{"):
            print txt
            error # deliberate error on lines with no {
        txt = txt.replace('if (', 'if ')
        txt = txt.replace('!', 'not ')
        txt = txt.replace('not =', '!=') # whoops
        txt = txt.replace(') {', ':')
    elif txt.endswith("else {"):
        txt = txt.replace('else {', 'else:')
    elif txt.find('class ') >= 0 and txt.endswith("{"):
        txt = txt.replace('{', ':')
    elif txt.find('try {') >= 0:
        txt = txt.replace('try {', 'try:')
    elif txt.find('} catch') >= 0:
        txt = txt.replace('} catch', 'except')
    elif txt.find('finally {') >= 0:
        txt = txt.replace('finally {', 'except:')
    elif txt.find('while (') >= 0:
        txt = txt.replace('while (', 'while ')
        txt = txt.replace(') {', ':')
    elif txt.find('for (') >= 0:
        txt = txt.replace('for (', 'for ')
        txt = txt.replace(') {', ':')
    count = countspaces(txt)
    if txt[count:].startswith("}"):
        txt = count * ' ' + txt[count+1:]

    if txt[count:].startswith("protected ") >= 0:
        # TODO: check if "class" in current line, add class name
        # otherwise assume last word of line is variable
        txt = txt.replace("protected ", "")
    if txt[count:].startswith("public ") >= 0:
        # TODO: check if "class" in current line, add class name
        # otherwise assume last word of line is variable
        txt = txt.replace("public ", "")
    if txt[count:].startswith("private ") >= 0:
        # TODO: check if "class" in current line, add class name
        # otherwise assume last word of line is variable e.g.
        # private final Area >>>targetArea<<<;
        txt = txt.replace("private ", "")
    if txt[count:].startswith("static ") >= 0:
        txt = txt.replace("static ", "")
    if txt[count:].startswith("native ") >= 0:
        txt = txt.replace("native ", "")
    if txt[count:].startswith("final ") >= 0:
        txt = txt.replace("final ", "")
    if txt.endswith(";"):
        txt = txt[:-1]
    if txt.endswith(" :"):
        txt = txt[:-2] + ":"

    return txt
dataset/ETHPy150Open anandology/pyjamas/contrib/java2py.py/java2pythonlinebyline/original