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
Nested ClassesModifier and TypeClassDescriptionstatic classClass.Builder<B extends Class.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionClass()Creates a new Class.Class(MemorySegment address) Create a Class proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionaddConstructor(@Nullable String name, @Nullable Callback callback, Type returnType, @Nullable Type @Nullable [] parameterTypes) Add a constructor tojscClass.Ifnameisnull, the class name will be used.addConstructorVariadic(@Nullable String name, @Nullable Callback callback, Type returnType) Add a constructor tojscClass.Ifnameisnull, the class name will be used.voidaddMethod(String name, @Nullable Callback callback, Type returnType, @Nullable Type @Nullable [] parameterTypes) Add method withnametojscClass.When the method is called by JavaScript or jsc_value_object_invoke_method(),callbackis called receiving the class instance as first parameter, followed by the method parameters and thenuserDataas last parameter.voidaddMethodVariadic(String name, @Nullable Callback callback, Type returnType) Add method withnametojscClass.When the method is called by JavaScript or jsc_value_object_invoke_method(),callbackis called receiving the class instance as first parameter, followed by aGPtrArrayofJSCValue<!-- -->s with the method arguments and thenuserDataas last parameter.voidaddProperty(String name, Type propertyType, @Nullable Callback getter, @Nullable Callback setter) Add a property withnametojscClass.When the property value needs to be getted,getteris called receiving the the class instance as first parameter anduserDataas last parameter.protected ClassasParent()Returns this instance as if it were its parent type.static Class.Builder<? extends Class.Builder> builder()AClass.Builderobject constructs aClasswith the specified properties.getName()Get the class name of this ClassGet the parent class of this Classstatic @Nullable TypegetType()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, 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, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.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
-
Class
public Class()Creates a new Class.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, 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 String name, @Nullable Callback callback, Type returnType) Add a constructor tojscClass.Ifnameisnull, the class name will be used. When <function>new</function> is used with the constructor or jsc_value_constructor_call() is called,callbackis invoked receiving aGPtrArrayofJSCValue<!-- -->s as arguments anduserDataas the last parameter. When the constructor object is cleared in theJSCClasscontext,destroyNotifyis called withuserDataas 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
callbackis adopted byjscClass,and theGDestroyNotifypassed to jsc_context_register_class() is responsible for disposing of it.- Parameters:
name- the constructor name ornullcallback- aGCallbackto be called to create an instance of this ClassreturnType- theGTypeof the constructor return value- Returns:
- a
JSCValuerepresenting the class constructor.
-
addConstructor
public Value addConstructor(@Nullable String name, @Nullable Callback callback, Type returnType, @Nullable Type @Nullable [] parameterTypes) Add a constructor tojscClass.Ifnameisnull, the class name will be used. When <function>new</function> is used with the constructor or jsc_value_constructor_call() is called,callbackis invoked receiving the parameters anduserDataas the last parameter. When the constructor object is cleared in theJSCClasscontext,destroyNotifyis called withuserDataas 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
callbackis adopted byjscClass,and theGDestroyNotifypassed to jsc_context_register_class() is responsible for disposing of it.- Parameters:
name- the constructor name ornullcallback- aGCallbackto be called to create an instance of this ClassreturnType- theGTypeof the constructor return valueparameterTypes- a list ofGType<!-- -->s, one for each parameter, ornull- Returns:
- a
JSCValuerepresenting the class constructor.
-
addMethodVariadic
Add method withnametojscClass.When the method is called by JavaScript or jsc_value_object_invoke_method(),callbackis called receiving the class instance as first parameter, followed by aGPtrArrayofJSCValue<!-- -->s with the method arguments and thenuserDataas last parameter. When the method is cleared in theJSCClasscontext,destroyNotifyis called withuserDataas parameter.Note that the value returned by
callbackmust be transfer full. In case of non-refcounted boxed types, you should useG_TYPE_POINTERinstead of the actual boxedGTypeto ensure that the instance owned byJSCClassis used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUEand return aJSCValuecreated with jsc_value_new_object() that receives the copy as the instance parameter.- Parameters:
name- the method namecallback- aGCallbackto be called to invoke methodnameof this ClassreturnType- theGTypeof the method return value, orG_TYPE_NONEif the method is void.
-
addMethod
public void addMethod(String name, @Nullable Callback callback, Type returnType, @Nullable Type @Nullable [] parameterTypes) Add method withnametojscClass.When the method is called by JavaScript or jsc_value_object_invoke_method(),callbackis called receiving the class instance as first parameter, followed by the method parameters and thenuserDataas last parameter. When the method is cleared in theJSCClasscontext,destroyNotifyis called withuserDataas parameter.Note that the value returned by
callbackmust be transfer full. In case of non-refcounted boxed types, you should useG_TYPE_POINTERinstead of the actual boxedGTypeto ensure that the instance owned byJSCClassis used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUEand return aJSCValuecreated with jsc_value_new_object() that receives the copy as the instance parameter.- Parameters:
name- the method namecallback- aGCallbackto be called to invoke methodnameof this ClassreturnType- theGTypeof the method return value, orG_TYPE_NONEif the method is void.parameterTypes- a list ofGType<!-- -->s, one for each parameter, ornull
-
addProperty
public void addProperty(String name, Type propertyType, @Nullable Callback getter, @Nullable Callback setter) Add a property withnametojscClass.When the property value needs to be getted,getteris called receiving the the class instance as first parameter anduserDataas last parameter. When the property value needs to be set,setteris called receiving the the class instance as first parameter, followed by the value to be set and thenuserDataas the last parameter. When the property is cleared in theJSCClasscontext,destroyNotifyis called withuserDataas parameter.Note that the value returned by
gettermust be transfer full. In case of non-refcounted boxed types, you should useG_TYPE_POINTERinstead of the actual boxedGTypeto ensure that the instance owned byJSCClassis used. If you really want to return a new copy of the boxed type, useJSC_TYPE_VALUEand return aJSCValuecreated with jsc_value_new_object() that receives the copy as the instance parameter.- Parameters:
name- the property namepropertyType- theGTypeof the property valuegetter- aGCallbackto be called to get the property valuesetter- aGCallbackto be called to set the property value
-
getName
-
getParent
-
builder
AClass.Builderobject constructs aClasswith the specified properties. Use the variousset...()methods to set properties, and finish construction withClass.Builder.build().- Returns:
- the builder object
-