# Path: pyjvm/jassert.py
# def jassert_array(array):
#     assert array is None or isinstance(array, JArray)
# 
# Path: pyjvm/utils.py
# def str_to_string(vm, ref):
#     '''Convert java string reference to unicode'''
#     if ref is None:
#         return "NULL"
#     heap_string = vm.heap[ref[1]]
#     value_ref = heap_string.fields["value"]
#     value = vm.heap[value_ref[1]]  # this is array of chars
#     return arr_to_string(value.values)


import os
import logging
import sys
from pyjvm.jassert import jassert_array
from pyjvm.utils import str_to_string


def vmo5_getPathSeparator___C(frame, args):
    '''Do not check operating system'''
    frame.stack.append(ord(':'))


def vmo5_normalize__Ljava_lang_String__Ljava_lang_String_(frame, args):
    '''Normalize according api rules'''
    s_ref = args[1]
    value = str_to_string(frame.vm, s_ref)
    norm = os.path.normpath(value)
    if value != norm:
        s_ref = frame.vm.make_heap_string(norm)
    frame.stack.append(s_ref)


def vmo5_prefixLength__Ljava_lang_String__I(frame, args):
    '''This is shortcut'''
    # s_ref = args[1]
    # value = str_to_string(frame.vm, s_ref)
    frame.stack.append(0)  # for now


def vmo5_getBooleanAttributes__Ljava_io_File__I(frame, args):
    '''See javadoc for details. Subset of all attributes is supported'''
    ref = args[1]
    assert ref is not None  # NPE
    o = frame.vm.heap[ref[1]]
    path_ref = o.fields['path']

# Path: pyjvm/jassert.py
# def jassert_array(array):
#     assert array is None or isinstance(array, JArray)
# 
# Path: pyjvm/utils.py
# def str_to_string(vm, ref):
#     '''Convert java string reference to unicode'''
#     if ref is None:
#         return "NULL"
#     heap_string = vm.heap[ref[1]]
#     value_ref = heap_string.fields["value"]
#     value = vm.heap[value_ref[1]]  # this is array of chars
#     return arr_to_string(value.values)


# Path: pyjvm/vmo.py
import os
import logging
import sys
from pyjvm.jassert import jassert_array
from pyjvm.utils import str_to_string



def vmo5_getPathSeparator___C(frame, args):
    '''Do not check operating system'''
    frame.stack.append(ord(':'))


def vmo5_normalize__Ljava_lang_String__Ljava_lang_String_(frame, args):
    '''Normalize according api rules'''
    s_ref = args[1]
    value = str_to_string(frame.vm, s_ref)
    norm = os.path.normpath(value)
    if value != norm:
        s_ref = frame.vm.make_heap_string(norm)
    frame.stack.append(s_ref)


def vmo5_prefixLength__Ljava_lang_String__I(frame, args):
    '''This is shortcut'''
    # s_ref = args[1]
    # value = str_to_string(frame.vm, s_ref)
    frame.stack.append(0)  # for now


def vmo5_getBooleanAttributes__Ljava_io_File__I(frame, args):
    '''See javadoc for details. Subset of all attributes is supported'''
    ref = args[1]
    assert ref is not None  # NPE
    o = frame.vm.heap[ref[1]]
    path_ref = o.fields['path']

    path = str_to_string(frame.vm, path_ref)