Package org.javagi.gobject.types
Class TypeCache
java.lang.Object
org.javagi.gobject.types.TypeCache
A register of GTypes with a Java constructor for each GType.
Using this register, the correct Java class is always instantiated, based on
the GType of the native object instance.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Check if this class is already cached.static Function
<MemorySegment, ? extends Proxy> getConstructor
(MemorySegment address, Function<MemorySegment, ? extends Proxy> fallback) Get the constructor from the type registry for the native object instance at the given memory address.static Function
<MemorySegment, ? extends Proxy> getConstructor
(@NotNull Type type, @Nullable Function<MemorySegment, ? extends Proxy> fallback) Get the constructor from the type registry for the provided GType.static Type
Return the GType that was registered for this class.static Function
<MemorySegment, ? extends Proxy> getTypeClassConstructor
(@NotNull Type type) static void
register
(Class<?> cls, Type type, Function<MemorySegment, ? extends Proxy> ctor, Function<MemorySegment, ? extends Proxy> typeClassCtor) Register the type and constructor function for the provided classstatic void
-
Constructor Details
-
TypeCache
public TypeCache()
-
-
Method Details
-
setTypeRegisterFunction
-
getConstructor
public static Function<MemorySegment,? extends Proxy> getConstructor(MemorySegment address, Function<MemorySegment, ? extends Proxy> fallback) Get the constructor from the type registry for the native object instance at the given memory address. The applicable constructor is determined based on the GType of the native object (as it was registered usingregister(Class, Type, Function, Function)
).- Parameters:
address
- address of TypeInstance object to obtain the type fromfallback
- if none was found, this constructor will be registered for the type, and returned- Returns:
- the constructor, or
null
if address isnull
or a null-pointer
-
getConstructor
public static Function<MemorySegment,? extends Proxy> getConstructor(@NotNull @NotNull Type type, @Nullable @Nullable Function<MemorySegment, ? extends Proxy> fallback) Get the constructor from the type registry for the provided GType. If it isn't found, we are probably dealing with an anonymous subclass or interface implementation. So we try to find a constructor for the parent type and the implemented interfaces. If that works, it is registered as the constructor for the GType and returned. Otherwise, the provided fallback constructor is registered and returned.- Parameters:
type
- the GType for which the constructor was registeredfallback
- if none was found, this constructor will be registered for the type, and returned- Returns:
- the constructor, or
null
if address isnull
or a null-pointer
-
getType
-
getTypeClassConstructor
public static Function<MemorySegment,? extends Proxy> getTypeClassConstructor(@NotNull @NotNull Type type) -
register
public static void register(Class<?> cls, Type type, Function<MemorySegment, ? extends Proxy> ctor, Function<MemorySegment, ? extends Proxy> typeClassCtor) Register the type and constructor function for the provided class- Parameters:
cls
- Class in Javatype
- The registered GTypector
- Constructor function for this type
-
contains
Check if this class is already cached.- Parameters:
cls
- the class to check- Returns:
- true when the class is cached in the TypeCache
-