Search in sources :

Example 1 with Bridge

use of org.robovm.rt.bro.annotation.Bridge in project robovm by robovm.

the class ObjCRuntime method bind.

public static void bind(Class<?> c) {
    for (Method method : c.getDeclaredMethods()) {
        Bridge bridge = method.getAnnotation(Bridge.class);
        if (bridge != null && (bridge.symbol() == null || "".equals(bridge.symbol()))) {
            Class<?>[] paramTypes = method.getParameterTypes();
            if (paramTypes.length >= 2) {
                // or (super, selector).
                if (paramTypes[1] == Selector.class) {
                    String symbol = null;
                    if (paramTypes[0] == ObjCSuper.class) {
                        symbol = "objc_msgSendSuper";
                    } else if (ObjCObject.class.isAssignableFrom(paramTypes[0])) {
                        // self should be an instance of ObjCObject
                        symbol = "objc_msgSend";
                    } else if (paramTypes[0] == long.class) {
                        // Also allow @Pointer long as type of self
                        Annotation[] paramAnnos = method.getParameterAnnotations()[0];
                        for (Annotation a : paramAnnos) {
                            if (a.annotationType() == Pointer.class) {
                                symbol = "objc_msgSend";
                                break;
                            }
                        }
                    }
                    if (symbol != null) {
                        // special stret versions of objc_msgSend/objc_msgSendSuper.
                        if (isStret(method)) {
                            symbol += "_stret";
                        }
                        long f = Runtime.resolveBridge("objc", symbol, method);
                        VM.bindBridgeMethod(method, f);
                    }
                }
            }
        }
    }
    Bro.bind(c);
}
Also used : Method(java.lang.reflect.Method) Bridge(org.robovm.rt.bro.annotation.Bridge) Annotation(java.lang.annotation.Annotation)

Aggregations

Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 Bridge (org.robovm.rt.bro.annotation.Bridge)1