Skip to content

LibraryRegistry ​

com.jsmacrosce.jsmacros.core.library.LibraryRegistry

Registers library classes and supplies applicable instances as globals for script runs.
Instances are shared, created per language, per execution, or per execution and language,
according to the library superclass.

Constructors ​

new LibraryRegistry ​

new LibraryRegistry(Core<?, ?> runner)#
Stores the core used to instantiate shared and per-language libraries during registration.

Parameters:

  • runner: core used for subsequent library instantiation

Fields ​

libraries ​

libraries: Map<Library, BaseLibrary>read-only#
Libraries instantiated once when registered and then shared, keyed by their Library annotation.

perExec ​

perExec: Map<Library, Class<? extends PerExecLibrary>>read-only#
Per-execution library classes; each applicable class is instantiated for a script run using a BaseScriptContext.

perExecLanguage ​

perExecLanguage: Map<Class<? extends BaseLanguage<?, ?>>, Map<Library, Class<? extends PerExecLanguageLibrary<?, ?>>>>read-only#
Per-execution, per-language library classes, keyed by their registered language class. Applicable classes are instantiated for each run with its context and the language class.

perLanguage ​

perLanguage: Map<Class<? extends BaseLanguage<?, ?>>, Map<Library, PerLanguageLibrary>>read-only#
Per-language instances, keyed by the language class used at registration. A language class also receives entries registered for its superclasses.

Methods ​

addLibraries ​

addLibraries(Iterable<Class<? extends BaseLibrary>> classes): void#
Registers several libraries as one batch. If any registration fails, every registry map is restored to its state before the batch and the failure is rethrown, so an extension whose later library fails does not leave its earlier globals usable.

Parameters:

  • classes: library classes to register in order

addLibrary ​

addLibrary(Class<? extends BaseLibrary> clazz): void#
Registers a library class, instantiating shared and per-language kinds immediately and storing per-execution kinds for later construction. The superclass determines the kind. Registration requires a Library annotation; per-language construction uses a Core and the registered language class, while shared construction uses a Core. This method is synchronized.

Parameters:

  • clazz: the library class to register
addLibrary(Class<? extends BaseLibrary> clazz, List<Class<? extends BaseLanguage<?, ?>>> languages): void#
Registers a library class that is restricted to the given languages. The languages are supplied separately rather than only through the Library annotation because a generated library class is defined by the core's class loader, while the language it is restricted to may live in an extension's loader. A class reference in an annotation is resolved against the loader that defined the annotated class, so such a reference could not be read back. The supplied languages take precedence over the ones in the annotation. For shared and per-execution libraries they restrict which languages receive the stored instance; for per-language libraries they select the registration keys.

Parameters:

  • clazz: the library class to register
  • languages: the languages the library applies to; empty means the annotation decides

getLibraries ​

getLibraries(BaseLanguage<?, ?> language, BaseScriptContext<?> context): Map<String, BaseLibrary>#
Returns applicable shared and per-execution libraries. Per-execution instances are constructed by this call; shared instances are reused.

Parameters:

  • language: the language the script is being run in
  • context: the run context used to construct per-execution libraries
Returns: libraries keyed by their Library global names

getOnceLibraries ​

getOnceLibraries(BaseLanguage<?, ?> language): Map<String, BaseLibrary>#
Returns shared libraries registered for all languages or this exact language, plus per-language instances registered for this language or one of its superclasses.

Parameters:

  • language: the language the libraries are being asked for
Returns: libraries keyed by their Library global names

getPerExecLibraries ​

getPerExecLibraries(BaseLanguage<?, ?> language, BaseScriptContext<?> context): Map<String, BaseLibrary>#
Constructs and returns applicable per-execution libraries. Construction failures are wrapped in a RuntimeException.

Parameters:

  • language: the language the libraries are being asked for
  • context: the run context used to construct libraries
Returns: libraries keyed by their Library global names