public static ObjCClass getFromObject(long handle) { long classPtr = ObjCRuntime.object_getClass(handle); return toObjCClass(classPtr); }
@MarshalsPointer public static Class<? extends ObjCObject> toObject(Class<ObjCClass> cls, long handle, long flags) { ObjCClass o = ObjCClass.toObjCClass(handle); if (o == null) { return null; } return o.getType(); } @MarshalsPointer
return (T) ObjCClass.toObjCClass(handle);
private static void registerCallbackMethod(long cls, long selector, long newSelector, Method method) { long superMethod = ObjCRuntime.class_getInstanceMethod(cls, selector); long typeEncoding = ObjCRuntime.method_getTypeEncoding(superMethod); if (!ObjCRuntime.class_addMethod(cls, selector, VM.getCallbackMethodImpl(method), typeEncoding)) { throw new Error( "Failed to register callback method on the ObjectOwnershipHelper: class_addMethod(...) failed"); } // find the super class that is a native class and cache it long superClass = ObjCRuntime.class_getSuperclass(cls); long nativeSuper = 0; while (superClass != 0) { ObjCClass objCClass = ObjCClass.toObjCClass(superClass); if (!objCClass.isCustom()) { nativeSuper = superClass; break; } superClass = ObjCRuntime.class_getSuperclass(superClass); } if (nativeSuper == 0) { throw new Error("Couldn't find native super class for " + VM.newStringUTF(ObjCRuntime.class_getName(cls))); } synchronized (customClassToNativeSuper) { customClassToNativeSuper.put(cls, nativeSuper); } }
@Callback private static @Pointer long retain(@Pointer long self, @Pointer long sel) { int count = ObjCRuntime.int_objc_msgSend(self, retainCount); if (count <= 1) { synchronized (CUSTOM_OBJECTS) { ObjCClass cls = ObjCClass.toObjCClass(ObjCRuntime.object_getClass(self)); ObjCObject obj = ObjCObject.toObjCObject(cls.getType(), self, 0); CUSTOM_OBJECTS.put(self, obj); } } long cls = ObjCRuntime.object_getClass(self); if (logRetainRelease) { logRetainRelease(cls, self, count, true); } Super sup = new Super(self, getNativeSuper(cls)); return ObjCRuntime.ptr_objc_msgSendSuper(sup.getHandle(), sel); }
public static ObjCClass getFromObject(long handle) { long classPtr = ObjCRuntime.object_getClass(handle); return toObjCClass(classPtr); }
@MarshalsPointer public static Class<? extends ObjCObject> toObject(Class<ObjCClass> cls, long handle, long flags) { ObjCClass o = ObjCClass.toObjCClass(handle); if (o == null) { return null; } return o.getType(); } @MarshalsPointer
return (T) ObjCClass.toObjCClass(handle);
private static void registerCallbackMethod(long cls, long selector, long newSelector, Method method) { long superMethod = ObjCRuntime.class_getInstanceMethod(cls, selector); long typeEncoding = ObjCRuntime.method_getTypeEncoding(superMethod); if (!ObjCRuntime.class_addMethod(cls, selector, VM.getCallbackMethodImpl(method), typeEncoding)) { throw new Error( "Failed to register callback method on the ObjectOwnershipHelper: class_addMethod(...) failed"); } // find the super class that is a native class and cache it long superClass = ObjCRuntime.class_getSuperclass(cls); long nativeSuper = 0; while (superClass != 0) { ObjCClass objCClass = ObjCClass.toObjCClass(superClass); if (!objCClass.isCustom()) { nativeSuper = superClass; break; } superClass = ObjCRuntime.class_getSuperclass(superClass); } if (nativeSuper == 0) { throw new Error("Couldn't find native super class for " + VM.newStringUTF(ObjCRuntime.class_getName(cls))); } synchronized (customClassToNativeSuper) { customClassToNativeSuper.put(cls, nativeSuper); } }