Class ReferenceResolvingPreprocessor

java.lang.Object
tech.guilhermekaua.spigotboot.config.reference.ReferenceResolvingPreprocessor
All Implemented Interfaces:
ConfigNodePreprocessor

public class ReferenceResolvingPreprocessor extends Object implements 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 Details

    • ReferenceResolvingPreprocessor

      public ReferenceResolvingPreprocessor(@NotNull @NotNull ConfigReferenceResolver resolver)
      Creates a new preprocessor.
      Parameters:
      resolver - the reference resolver
  • Method Details

    • setCurrentSourceKey

      public void setCurrentSourceKey(@NotNull @NotNull ReferenceKey sourceKey)
      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

      @Nullable public @Nullable ReferenceKey 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: ConfigNodePreprocessor
      Preprocesses 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:
      preprocess in interface ConfigNodePreprocessor
      Parameters:
      node - the original config node
      field - 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