Class ConfigReferenceResolver

java.lang.Object
tech.guilhermekaua.spigotboot.config.reference.ConfigReferenceResolver

public class ConfigReferenceResolver extends Object
Resolves config references (${...}) to their target values.

This resolver supports:

  • Single config references: ${configName} or ${configName:path}
  • Folder config item references: ${folderConfigName.itemId} or ${folderConfigName.itemId:path}
  • Deep/recursive resolution: references inside resolved values are also resolved
  • Cycle detection: prevents infinite loops in circular references
  • Constructor Details

    • ConfigReferenceResolver

      public ConfigReferenceResolver(@NotNull @NotNull ConfigReferenceLookup lookup, @NotNull @NotNull ConfigReferenceParser parser, @NotNull @NotNull ConfigReferenceErrorHandler errorHandler)
      Creates a new resolver.
      Parameters:
      lookup - the lookup for finding config nodes
      parser - the parser for parsing reference tokens
      errorHandler - the handler for resolution errors
  • Method Details

    • resolveIfReference

      @Nullable public @Nullable ConfigNode resolveIfReference(@NotNull @NotNull ConfigNode node, @NotNull @NotNull ReferenceKey sourceKey, @Nullable @Nullable Field sourceField)
      Resolves a config node if it's a reference.

      If the node is a scalar string that matches the reference pattern, it will be resolved to the target node. Otherwise, the original node is returned unchanged.

      Parameters:
      node - the node to potentially resolve
      sourceKey - the key of the config containing this node
      sourceField - the field being bound (may be null)
      Returns:
      the resolved node, or null if reference not found
    • resolveIfReference

      @Nullable public @Nullable ConfigNode resolveIfReference(@NotNull @NotNull ConfigNode node, @NotNull @NotNull ReferenceKey sourceKey, @Nullable @Nullable Field sourceField, @Nullable @Nullable Type expectedType)
      Resolves a config node if it's a reference, checking the resolved value against an expected target type.

      Behaves like resolveIfReference(ConfigNode, ReferenceKey, Field), but when expectedType is provided and the resolved value cannot be coerced into it, ConfigReferenceErrorHandler.onTypeMismatch(ConfigTypeMismatchContext) is invoked.

      Parameters:
      node - the node to potentially resolve
      sourceKey - the key of the config containing this node
      sourceField - the field being bound (may be null)
      expectedType - the expected target type, or null to skip the type-mismatch check
      Returns:
      the resolved node, or null if reference not found
    • deepResolve

      @NotNull public @NotNull ConfigNode deepResolve(@NotNull @NotNull ConfigNode node, @NotNull @NotNull ReferenceKey sourceKey)
      Deeply resolves all references in a config node tree.

      This walks the entire tree and resolves any reference values found, including nested references.

      Parameters:
      node - the root node to resolve
      sourceKey - the key of the config this node belongs to
      Returns:
      the resolved node tree
    • isReference

      public boolean isReference(@Nullable @Nullable String value)
      Checks if a string value is a reference.
      Parameters:
      value - the string value
      Returns:
      true if it's a reference pattern