Class ReferenceResolvingPreprocessor
java.lang.Object
tech.guilhermekaua.spigotboot.config.reference.ReferenceResolvingPreprocessor
- All Implemented Interfaces:
ConfigNodePreprocessor
A
ConfigNodePreprocessor that resolves config references (${...}).
This preprocessor wraps a ConfigReferenceResolver and adapts it to the
binder's preprocessor API. It is used during config binding to resolve any
reference values before they are deserialized.
The preprocessor maintains a "current source key" which identifies the config or folder config item currently being bound. This is used for cycle detection and error reporting.
-
Constructor Summary
ConstructorsConstructorDescriptionReferenceResolvingPreprocessor(@NotNull ConfigReferenceResolver resolver) Creates a new preprocessor. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the current source key.@Nullable ReferenceKeyGets the current source key.@Nullable ConfigNodepreprocess(@NotNull ConfigNode node, @Nullable Field field, @NotNull Type expectedType) Preprocesses a config node before binding.voidsetCurrentSourceKey(@NotNull ReferenceKey sourceKey) Sets the current source key for binding context.
-
Constructor Details
-
ReferenceResolvingPreprocessor
Creates a new preprocessor.- Parameters:
resolver- the reference resolver
-
-
Method Details
-
setCurrentSourceKey
Sets the current source key for binding context.This should be called before binding each config or folder config item to provide context for error reporting and cycle detection.
- Parameters:
sourceKey- the key of the config being bound
-
clearCurrentSourceKey
public void clearCurrentSourceKey()Clears the current source key. -
getCurrentSourceKey
Gets the current source key.- Returns:
- the current source key, or null if not set
-
preprocess
@Nullable public @Nullable ConfigNode preprocess(@NotNull @NotNull ConfigNode node, @Nullable @Nullable Field field, @NotNull @NotNull Type expectedType) Description copied from interface:ConfigNodePreprocessorPreprocesses a config node before binding.This method is called for each node before deserialization. If the preprocessor handles the node (e.g., resolves a reference), it should return the resolved node. Otherwise, return null to use the original.
- Specified by:
preprocessin interfaceConfigNodePreprocessor- Parameters:
node- the original config nodefield- the field being bound (may be null for constructor params or root binding)expectedType- the expected type of the value- Returns:
- the preprocessed node, or null to use the original
-