package org.ngscript.runtime.vo;

import org.ngscript.runtime.utils.TypeCheck;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MethodTypeMap {

    Map<String, Method> map = new HashMap<>();

    public static MethodTypeMap INSTANCE = new MethodTypeMap();

    private MethodTypeMap() {
    }

    public Method getProperMethod(String methodName, List<Method> methods, Class[] types) {
        if (methods.size() == 1) {
            return methods.get(0);
        } else {
            int typeHash = typeHash(types);
            String key = methodName + "#" + typeHash;
            if (map.containsKey(key)) {
                return map.get(key);
            } else {
                for (Method m : methods) {
                    if (TypeCheck.typeAcceptable(types, m.getParameterTypes())) {
                        map.put(key, m);
                        return m;
                    }
                }
            }
        }
        return null;
    }

    int typeHash(Class[] types) {
        int hash = 0;
        for (Class type : types) {
            hash = (hash >> 12 | hash << 20) ^ type.hashCode();
        }
        return hash;
    }
}

@@ -106,16 +106,51 @@
 Method;%0A
+import java.lang.reflect.Modifier;%0A
 import j
@@ -807,24 +807,150 @@
  methods) %7B%0A
+                    if (Modifier.isPublic(m.getDeclaringClass().getModifiers()) && Modifier.isPublic(m.getModifiers())) %7B%0A    
             
@@ -1043,16 +1043,20 @@
         
+    
 map.put(
@@ -1080,32 +1080,36 @@
                 
+    
 return m;%0A      
@@ -1102,16 +1102,42 @@
 turn m;%0A
+                        %7D%0A
         

fix call for inner class