Search in sources :

Example 1 with ClassMethodFunction

use of com.googlecode.aviator.runtime.function.ClassMethodFunction in project aviatorscript by killme2008.

the class Reflector method retrieveStaticFunction.

private static PropertyFoundResult retrieveStaticFunction(final Map<String, PropertyFoundResult> results, final Class<?> clazz, final String name) throws IllegalAccessException, NoSuchMethodException {
    PropertyFoundResult result;
    List<Method> methods = getStaticMethods(clazz, name);
    if (methods != null && !methods.isEmpty()) {
        // cast the methods into a function.
        ClassMethodFunction func = new ClassMethodFunction(clazz, true, name, name, methods);
        result = new PropertyFoundResult(func);
    } else {
        result = new PropertyFoundResult(null);
    }
    results.put(name, result);
    return result;
}
Also used : ClassMethodFunction(com.googlecode.aviator.runtime.function.ClassMethodFunction) Method(java.lang.reflect.Method)

Example 2 with ClassMethodFunction

use of com.googlecode.aviator.runtime.function.ClassMethodFunction in project aviatorscript by killme2008.

the class AviatorEvaluatorInstance method loadModule.

private Env loadModule(final Class<?> moduleClazz) throws IllegalAccessException, NoSuchMethodException {
    Map<String, List<Method>> methodMap = findMethodsFromClass(moduleClazz, true);
    if (methodMap == null || methodMap.isEmpty()) {
        throw new IllegalArgumentException("Empty module");
    }
    Env exports = new Env();
    for (Map.Entry<String, List<Method>> entry : methodMap.entrySet()) {
        exports.put(entry.getKey(), new ClassMethodFunction(moduleClazz, true, entry.getKey(), entry.getKey(), entry.getValue()));
    }
    exports.setInstance(this);
    return exports;
}
Also used : ClassMethodFunction(com.googlecode.aviator.runtime.function.ClassMethodFunction) ArrayList(java.util.ArrayList) List(java.util.List) Env(com.googlecode.aviator.utils.Env) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LRUMap(com.googlecode.aviator.utils.LRUMap)

Example 3 with ClassMethodFunction

use of com.googlecode.aviator.runtime.function.ClassMethodFunction in project aviatorscript by killme2008.

the class AviatorEvaluatorInstance method addMethodFunctions.

private List<String> addMethodFunctions(final String namespace, final boolean isStatic, final Class<?> clazz) throws IllegalAccessException, NoSuchMethodException {
    Map<String, List<Method>> methodMap = findMethodsFromClass(clazz, isStatic);
    List<String> added = new ArrayList<>();
    for (Map.Entry<String, List<Method>> entry : methodMap.entrySet()) {
        String methodName = entry.getKey();
        String name = namespace + "." + methodName;
        this.addFunction(new ClassMethodFunction(clazz, isStatic, name, methodName, entry.getValue()));
        added.add(name);
    }
    return added;
}
Also used : ClassMethodFunction(com.googlecode.aviator.runtime.function.ClassMethodFunction) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LRUMap(com.googlecode.aviator.utils.LRUMap)

Aggregations

ClassMethodFunction (com.googlecode.aviator.runtime.function.ClassMethodFunction)3 LRUMap (com.googlecode.aviator.utils.LRUMap)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Env (com.googlecode.aviator.utils.Env)1 Method (java.lang.reflect.Method)1