Skip to main content

Module gen_visitor

Module gen_visitor 

Source
Expand description

Generate Java visitor support: interface, NodeContext record, VisitResult sealed interface, VisitorBridge (upcall stubs), and convertWithVisitor method.

§Panama FFM upcall strategy

Java cannot expose method references as raw C function pointers. The generated code uses Java 21+ Foreign Function & Memory API (Panama) upcall stubs:

  • NodeContext: a record carrying the fields from HTMHtmNodeContext.
  • VisitResult: a sealed interface with Continue, Skip, PreserveHtml, Custom, and Error implementations.
  • Visitor: an interface with default no-op methods for all 40 callbacks.
  • VisitorBridge: a package-private class that allocates one MemorySegment upcall stub per callback inside a Arena.ofConfined() scope, then writes all stubs into a flat MemorySegment matching HTMHtmVisitorCallbacks.
  • convertWithVisitor: static method on the wrapper class that drives the full lifecycle: marshal options → create VisitorBridgehtm_visitor_createhtm_convert_with_visitor → deserialise JSON result → htm_visitor_free.

Structs§

CallbackSpec
ExtraParam

Constants§

CALLBACKS

Functions§

gen_convert_with_visitor_method
Generate the convertWithVisitor method body to inject into the main wrapper class.
gen_native_lib_visitor_handles
Generate NativeLib method handle declarations for visitor FFI functions.
gen_visitor_files
Returns (filename, content) pairs for all visitor-related Java files.