Search in sources :

Example 1 with PyJavaFunctionObject

use of org.cafebabepy.runtime.object.java.PyJavaFunctionObject in project cafebabepy by cafebabepy.

the class AbstractAbstractCafeBabePyAny method defineClassMember.

private void defineClassMember(Class<?> clazz) {
    // Check duplicate
    Set<String> defineClassMemberNamesSet = new HashSet<>();
    for (Method method : clazz.getMethods()) {
        // Same class method only
        if (clazz != method.getDeclaringClass()) {
            continue;
        }
        DefinePyFunction definePyFunction = method.getAnnotation(DefinePyFunction.class);
        if (definePyFunction == null) {
            continue;
        }
        if (defineClassMemberNamesSet.contains(definePyFunction.name())) {
            throw new CafeBabePyException("Duplicate '" + definePyFunction.name() + "' function");
        }
        PyJavaFunctionObject f = new PyJavaFunctionObject(getRuntime(), this, definePyFunction.name(), method);
        if (__call__.equals(f.getName())) {
            f.getScope().put(__call__, f);
        }
        getScope().put(f.getName(), f);
        defineClassMemberNamesSet.add(definePyFunction.name());
    }
}
Also used : CafeBabePyException(org.cafebabepy.runtime.CafeBabePyException) Method(java.lang.reflect.Method) PyJavaFunctionObject(org.cafebabepy.runtime.object.java.PyJavaFunctionObject)

Aggregations

Method (java.lang.reflect.Method)1 CafeBabePyException (org.cafebabepy.runtime.CafeBabePyException)1 PyJavaFunctionObject (org.cafebabepy.runtime.object.java.PyJavaFunctionObject)1