package com.ninty.nativee.io;

import com.ninty.nativee.INativeMethod;
import com.ninty.nativee.NaMethodManager;
import com.ninty.runtime.NiFrame;

/**
 * Created by ninty on 2018/10/24
 */
public class NaUnixFileSystem {
    private final static String className = "java/io/UnixFileSystem";

    public static void init() {
        NaMethodManager.register(className, "initIDs", "()V",
                new initIDs());
        NaMethodManager.register(className, "getBooleanAttributes0", "(Ljava/io/File;)I",
                new getBooleanAttributes0());
    }

    public static class initIDs implements INativeMethod{
        @Override
        public void invoke(NiFrame frame) {
        }
    }

    public static class getBooleanAttributes0 implements INativeMethod{
        @Override
        public void invoke(NiFrame frame) {
            frame.getOperandStack().pushInt(0);
        }
    }
}

@@ -139,16 +139,202 @@
 NiFrame;
+%0Aimport com.ninty.runtime.heap.NiClass;%0Aimport com.ninty.runtime.heap.NiClassLoader;%0Aimport com.ninty.runtime.heap.NiObject;%0Aimport com.ninty.runtime.heap.NiString;%0A%0Aimport java.io.File;
 %0A%0A/**%0A *
@@ -730,24 +730,144 @@
 ibutes0());%0A
+        NaMethodManager.register(className, %22list%22, %22(Ljava/io/File;)%5BLjava/lang/String;%22,%0A                new list());%0A
     %7D%0A%0A    p
@@ -909,32 +909,33 @@
 ts INativeMethod
+ 
 %7B%0A        @Overr
@@ -1069,16 +1069,17 @@
 veMethod
+ 
 %7B%0A      
@@ -1197,11 +1197,919 @@
  %7D%0A    %7D
+%0A%0A    public static class list implements INativeMethod %7B%0A        @Override%0A        public void invoke(NiFrame frame) %7B%0A            NiObject fileObj = frame.getLocalVars().getRef(1);%0A            String path = NiString.getString(fileObj.getFieldRef(%22path%22, %22Ljava/lang/String;%22));%0A            File file = new File(path);%0A            String%5B%5D files = file.list();%0A            if(files == null)%7B%0A                frame.getOperandStack().pushRef(null);%0A                return;%0A            %7D%0A            NiClassLoader loader = frame.getMethod().getClz().getLoader();%0A            NiClass arrStr = loader.loadClass(%22%5Bjava/lang/String;%22);%0A            NiObject filesObj = arrStr.newArray(files.length);%0A            for (int i = 0; i %3C files.length; i++) %7B%0A                filesObj.aobject()%5Bi%5D = NiString.newString(loader, files%5Bi%5D);%0A            %7D%0A            frame.getOperandStack().pushRef(filesObj);%0A        %7D%0A    %7D
 %0A%7D%0A

add native method: java.io.UnixFileSystem.list(Ljava/io/File;)[Ljava/lang/String;