Class Class
- All Implemented Interfaces:
Proxy
JSCContext
.
It allows to create new JavaScripts objects whose instances are created by the user using
this API.
It's possible to add constructors, properties and methods for a JSSClass by providing
GCallback
<!-- -->s to implement them.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Class.Builder<B extends Class.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionClass
(MemorySegment address) Create a Class proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionaddConstructor
(@Nullable String name, Callback callback, Type returnType, @Nullable Type[] parameterTypes) Add a constructor to this Class.addConstructorVariadic
(@Nullable String name, Callback callback, Type returnType) Add a constructor to this Class.void
Add method withname
to this Class.void
addMethodVariadic
(String name, Callback callback, Type returnType) Add method withname
to this Class.void
addProperty
(String name, Type propertyType, @Nullable Callback getter, @Nullable Callback setter) Add a property withname
to this Class.protected Class
asParent()
Returns this instance as if it were its parent type.static Class.Builder
<? extends Class.Builder> builder()
AClass.Builder
object constructs aClass
with the specified properties.getName()
Get the class name of this ClassGet the parent class of this Classstatic Type
getType()
Get the GType of the Class classMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Class
Create a Class proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
addConstructorVariadic
public Value addConstructorVariadic(@Nullable @Nullable String name, Callback callback, Type returnType) Add a constructor to this Class. Ifname
isnull
, the class name will be used. When <function>new</function> is used with the constructor or jsc_value_constructor_call() is called,callback
is invoked receiving aGPtrArray
ofJSCValue
<!-- -->s as arguments anduserData
as the last parameter. When the constructor object is cleared in theJSCClass
context,destroyNotify
is called withuserData
as parameter.This function creates the constructor, which needs to be added to an object as a property to be able to use it. Use jsc_context_set_value() to make the constructor available in the global object.
Note that the value returned by
callback
is adopted by this Class, and theGDestroyNotify
passed to jsc_context_register_class() is responsible for disposing of it.- Parameters:
name
- the constructor name ornull
callback
- aGCallback
to be called to create an instance of this ClassreturnType
- theGType
of the constructor return value- Returns:
- a
JSCValue
representing the class constructor.
-
addConstructor
public Value addConstructor(@Nullable @Nullable String name, Callback callback, Type returnType, @Nullable @Nullable Type[] parameterTypes) Add a constructor to this Class. Ifname
isnull
, the class name will be used. When <function>new</function> is used with the constructor or jsc_value_constructor_call() is called,callback
is invoked receiving the parameters anduserData
as the last parameter. When the constructor object is cleared in theJSCClass
context,destroyNotify
is called withuserData
as parameter.This function creates the constructor, which needs to be added to an object as a property to be able to use it. Use jsc_context_set_value() to make the constructor available in the global object.
Note that the value returned by
callback
is adopted by this Class, and theGDestroyNotify
passed to jsc_context_register_class() is responsible for disposing of it.- Parameters:
name
- the constructor name ornull
callback
- aGCallback
to be called to create an instance of this ClassreturnType
- theGType
of the constructor return valueparameterTypes
- a list ofGType
<!-- -->s, one for each parameter, ornull
- Returns:
- a
JSCValue
representing the class constructor.
-
addMethodVariadic
Add method withname
to this Class. When the method is called by JavaScript or jsc_value_object_invoke_method(),callback
is called receiving the class instance as first parameter, followed by aGPtrArray
ofJSCValue
<!-- -->s with the method arguments and thenuserData
as last parameter. When the method is cleared in theJSCClass
context,destroyNotify
is called withuserData
as parameter.Note that the value returned by
callback
must be transfer full. In case of non-refcounted boxed types, you should useG_TYPE_POINTER
instead of the actual boxedGType
to ensure that the instance owned byJSCClass
is used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUE
and return aJSCValue
created with jsc_value_new_object() that receives the copy as the instance parameter.- Parameters:
name
- the method namecallback
- aGCallback
to be called to invoke methodname
of this ClassreturnType
- theGType
of the method return value, orG_TYPE_NONE
if the method is void.
-
addMethod
public void addMethod(String name, Callback callback, Type returnType, @Nullable @Nullable Type[] parameterTypes) Add method withname
to this Class. When the method is called by JavaScript or jsc_value_object_invoke_method(),callback
is called receiving the class instance as first parameter, followed by the method parameters and thenuserData
as last parameter. When the method is cleared in theJSCClass
context,destroyNotify
is called withuserData
as parameter.Note that the value returned by
callback
must be transfer full. In case of non-refcounted boxed types, you should useG_TYPE_POINTER
instead of the actual boxedGType
to ensure that the instance owned byJSCClass
is used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUE
and return aJSCValue
created with jsc_value_new_object() that receives the copy as the instance parameter.- Parameters:
name
- the method namecallback
- aGCallback
to be called to invoke methodname
of this ClassreturnType
- theGType
of the method return value, orG_TYPE_NONE
if the method is void.parameterTypes
- a list ofGType
<!-- -->s, one for each parameter, ornull
-
addProperty
public void addProperty(String name, Type propertyType, @Nullable @Nullable Callback getter, @Nullable @Nullable Callback setter) Add a property withname
to this Class. When the property value needs to be getted,getter
is called receiving the the class instance as first parameter anduserData
as last parameter. When the property value needs to be set,setter
is called receiving the the class instance as first parameter, followed by the value to be set and thenuserData
as the last parameter. When the property is cleared in theJSCClass
context,destroyNotify
is called withuserData
as parameter.Note that the value returned by
getter
must be transfer full. In case of non-refcounted boxed types, you should useG_TYPE_POINTER
instead of the actual boxedGType
to ensure that the instance owned byJSCClass
is used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUE
and return aJSCValue
created with jsc_value_new_object() that receives the copy as the instance parameter.- Parameters:
name
- the property namepropertyType
- theGType
of the property valuegetter
- aGCallback
to be called to get the property valuesetter
- aGCallback
to be called to set the property value
-
getName
-
getParent
-
builder
AClass.Builder
object constructs aClass
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withClass.Builder.build()
.
-