Class ConfigReferenceResolver
java.lang.Object
tech.guilhermekaua.spigotboot.config.reference.ConfigReferenceResolver
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 Summary
ConstructorsConstructorDescriptionConfigReferenceResolver(@NotNull ConfigReferenceLookup lookup, @NotNull ConfigReferenceParser parser, @NotNull ConfigReferenceErrorHandler errorHandler) Creates a new resolver. -
Method Summary
Modifier and TypeMethodDescription@NotNull ConfigNodedeepResolve(@NotNull ConfigNode node, @NotNull ReferenceKey sourceKey) Deeply resolves all references in a config node tree.booleanisReference(@Nullable String value) Checks if a string value is a reference.@Nullable ConfigNoderesolveIfReference(@NotNull ConfigNode node, @NotNull ReferenceKey sourceKey, @Nullable Field sourceField) Resolves a config node if it's a reference.@Nullable ConfigNoderesolveIfReference(@NotNull ConfigNode node, @NotNull ReferenceKey sourceKey, @Nullable Field sourceField, @Nullable Type expectedType) Resolves a config node if it's a reference, checking the resolved value against an expected target type.
-
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 nodesparser- the parser for parsing reference tokenserrorHandler- 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 resolvesourceKey- the key of the config containing this nodesourceField- 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 whenexpectedTypeis provided and the resolved value cannot be coerced into it,ConfigReferenceErrorHandler.onTypeMismatch(ConfigTypeMismatchContext)is invoked.- Parameters:
node- the node to potentially resolvesourceKey- the key of the config containing this nodesourceField- 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 resolvesourceKey- the key of the config this node belongs to- Returns:
- the resolved node tree
-
isReference
Checks if a string value is a reference.- Parameters:
value- the string value- Returns:
- true if it's a reference pattern
-