ObjCObjectMapper

public class ObjCObjectMapper implements Mapper

Mapper for Objective-C objects.

Fields

proxy2addr

public Map<Object, WeakReference> proxy2addr

Collection for caching the created Objective-C proxy objects.

type2ProtocolInfo

public Map<Class<?>, NativeProtocolInfo> type2ProtocolInfo

Collection for caching the created info of native protocol proxies.

Methods

cleanupObjCProxy

public void cleanupObjCProxy(Object peer)

Removes the object from the proxy map.

Parameters:
  • peer – Proxy object

createStrongBindingPointer

public static Pointer createStrongBindingPointer(long peer, boolean owned)

Creates a strong binding pointer to an Objective-C object.

Retains if doing so is needed to keep the strong ownership.

Parameters:
  • peer – The pointer
  • owned – If this is false, the pointer objects will be retained
Returns:

The created Pointer object

dispose

public boolean dispose(Object object)

Disposes an object if it can be.

Parameters:
  • object – The object of which we want to dispose the native peer
Returns:

Whether the given object was disposable

getNativePeerOfProxyedObject

public Pointer getNativePeerOfProxyedObject(Object object)

Returns the Objective-C object for a proxied Java instance.

Parameters:
  • object – The object we want to get native proxy object for.
Returns:

The native proxy object

toJava

public Object toJava(long peer, JavaObjectConstructionInfo info)

Creates Java objects from Objective-C objects.

For NativeObjects this will use the Java instances associated with the Objective-C objects. If there are no references, then this will create new NativeObjects, and associate them with the Objective-C objects. For strings this will forward to ObjCStringMapper. For blocks this will forward to ObjCCallbackMapper.

For proxies it will return the the Java instances associated with the Objective-C proxy objects.

toNative

public long toNative(Object instance, NativeObjectConstructionInfo info)

Creates Objective-C objects from Java objects.

For NativeObjects this will only return their peers. For strings this will forward to ObjCStringMapper. For every other cases this will generate proxy classes with using class2addr as cache for Objective-C classes, and instance them with using proxy2addr as a cache for instantiations.