Class ConverterRegistry
java.lang.Object
com.ultikits.ultitools.config.convert.ConverterRegistry
Module-local converter lookup and pre-file type validation.
Prepared registries are published after converter discovery; selected entities are checked separately.
No cached value retains the module instance used as its weak key.
- Since:
- 6.3.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classprivate static final classstatic final classOutcome ofConverterRegistry.Context.probe(java.lang.Object, java.lang.reflect.Type): whether the read succeeded without any failure, and the value it read.private static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ConverterRegistryprivate static final Map<UltiToolsPlugin, ConverterRegistry.Prepared> private final ConverterRegistryprivate final Map<Class<?>, ConverterRegistry.Registration> private boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionFile-key ambiguity scan: finds every typed map key that two or more of the file's own keys at one map level read back to (1:and'01':in aMap<Integer, String>), decided from the file's keys alone - no Java value is involved, so a key the module removed or never held still counts.voidcheckEntityFields(Class<?> entity, String module, String file) Checks every annotated field and every generic argument without reading or writing a file.private static ConverterRegistryprivate static Stringprivate voidstatic ConverterRegistryforModule(UltiToolsPlugin plugin) static ConverterRegistry<T> TConverts a document value through this registry.<T> ConversionResult<T> Converts with an internal diagnostic collector shared by every nested context.<T> ConversionResult<T> fromPlainResult(Object plain, Type type, String file, List<String> path, ConfigEntry entry) Selects an explicitly declared legacy parser before registry conversion.static booleanhasModule(UltiToolsPlugin plugin) private static booleanhasRegisteredAlias(Class<?> raw) private static booleanheldInSeveralSpellings(List<String> spellings) private <T> TinvokeRead(ConfigConverter<?> converter, Object plain, ConverterRegistry.Context ctx) private ObjectinvokeWrite(ConfigConverter<Object> converter, Object value, ConverterRegistry.Context ctx) private TypemissingType(Type type, Set<Type> visiting) static ConverterRegistryprepareModule(UltiToolsPlugin plugin, String[] packages, ClassLoader loader) Discovers all converters before publishing the registry, without selecting config entities.prepareSelectedConfigs(UltiToolsPlugin plugin, String[] packages, ClassLoader loader) Checks exactly the requested auto-registration batch before any entity is constructed.(package private) static Class<?> private <T> Tread(Object plain, ConverterRegistry.Context ctx) private ObjectreadSerializable(Object plain, Class<? extends org.bukkit.configuration.serialization.ConfigurationSerializable> factory, ConverterRegistry.Context ctx) voidregister(Class<?> type, ConfigConverter<?> converter, boolean exact) Registers a converter without replacing an existing exact target registration.private ConfigConverter<?> registered(Class<?> raw) Resolves local hierarchy first, then parent hierarchy, then generic and serializable hooks.private voidscanFileKeys(ConverterRegistry.Context ctx, List<List<String>> found) Descends where the writer descends: only through declared types the generic converter writes.private voidscanFileList(ConverterRegistry.Context ctx, Class<?> raw, List<List<String>> found) Scans each list element by its index, where the declared type is an array or a collection.private voidscanFileMap(ConverterRegistry.Context ctx, List<List<String>> found) Reports this map level's ambiguous typed keys, then scans every entry's value by its file key text.Converts a Java value and enforces the storage plain-data boundary even for custom output.Selects an explicitly declared legacy parser before registry conversion.toPlainResult(Object value, Type type, String file, List<String> path, ConfigEntry entry) Internal write-planning bridge; inspection callers may discard the located omissions.toPlainResult(Object value, Type type, String file, List<String> path, ConfigEntry entry, Object fileValue) Internal write-planning bridge that also takes the plain value the file holds atpath.private Objectwrite(Object value, ConverterRegistry.Context ctx)
-
Field Details
-
MODULES
-
FRAMEWORK
-
parent
-
registrations
-
sealed
private boolean sealed
-
-
Constructor Details
-
ConverterRegistry
- Parameters:
parent- the parent registry, or null for an independent root
-
-
Method Details
-
framework
- Returns:
- the shared framework registry
-
registeredTypes
- Returns:
- actual scalar registrations and implementation-owned generic factory categories
-
createFramework
-
register
Registers a converter without replacing an existing exact target registration.- Parameters:
type- the target classconverter- the converterexact- whether subclass lookup is forbidden
-
resolve
Resolves local hierarchy first, then parent hierarchy, then generic and serializable hooks.- Parameters:
type- the full declared type- Returns:
- the converter, or null if no supported conversion exists
-
registered
-
prepareModule
public static ConverterRegistry prepareModule(UltiToolsPlugin plugin, String[] packages, ClassLoader loader) Discovers all converters before publishing the registry, without selecting config entities. Repeating the same package set is idempotent; extending it discovers the union atomically.- Parameters:
plugin- the module used only as a weak cache keypackages- the complete package set for this preparationloader- the module class loader- Returns:
- the prepared immutable registry
-
prepareSelectedConfigs
public static Set<Class<?>> prepareSelectedConfigs(UltiToolsPlugin plugin, String[] packages, ClassLoader loader) Checks exactly the requested auto-registration batch before any entity is constructed. Discovery caching never skips selection or validation; empty config paths remain ignored.- Parameters:
plugin- the module selecting the batchpackages- exactly the packages selected for this registrationloader- the class loader used by the selected scan- Returns:
- the selected config classes, all checked before the caller constructs any
-
discover
-
hasModule
- Parameters:
plugin- the module- Returns:
- whether preparation has succeeded for it
-
forModule
- Parameters:
plugin- the module- Returns:
- its prepared registry, or the framework registry
-
checkEntityFields
Checks every annotated field and every generic argument without reading or writing a file. A nondefault legacy parser owns conversion and is adapted separately.- Parameters:
entity- the config class, including inherited fieldsmodule- the module namefile- the module-relative config file
-
missingType
-
hasRegisteredAlias
-
describe
-
rawClass
-
toPlain
public Object toPlain(Object value, Type type, String file, List<String> path) throws ConversionException Converts a Java value and enforces the storage plain-data boundary even for custom output.- Parameters:
value- the Java valuetype- its declared typefile- the module-relative filepath- the whole keys- Returns:
- plain data
- Throws:
ConversionException- when conversion or plain-data validation fails
-
fromPlain
public <T> T fromPlain(Object plain, Type type, String file, List<String> path) throws ConversionException Converts a document value through this registry.- Type Parameters:
T- the result type- Parameters:
plain- the document valuetype- the declared Java typefile- the module-relative filepath- the whole keys- Returns:
- the converted value
- Throws:
ConversionException- on a root conversion failure
-
fromPlainResult
public <T> ConversionResult<T> fromPlainResult(Object plain, Type type, String file, List<String> path) throws ConversionException Converts with an internal diagnostic collector shared by every nested context.- Type Parameters:
T- the result type- Parameters:
plain- the document valuetype- the declared typefile- the module-relative filepath- the whole keys- Returns:
- the value and all collected nested failures
- Throws:
ConversionException- on a scalar-root failure
-
toPlain
public Object toPlain(Object value, Type type, String file, List<String> path, ConfigEntry entry) throws ConversionException Selects an explicitly declared legacy parser before registry conversion.- Parameters:
value- Java valuetype- declared typefile- configuration filepath- whole keysentry- annotation, or null for registry conversion- Returns:
- plain data
- Throws:
ConversionException- on conversion failure
-
toPlainResult
@Internal public ConversionResult<Object> toPlainResult(Object value, Type type, String file, List<String> path, ConfigEntry entry) throws ConversionException Internal write-planning bridge; inspection callers may discard the located omissions.- Parameters:
value- Java valuetype- declared typefile- configuration filepath- whole keysentry- annotation, or null for registry conversion- Returns:
- plain value and collected nested omissions
- Throws:
ConversionException- on conversion failure
-
toPlainResult
@Internal public ConversionResult<Object> toPlainResult(Object value, Type type, String file, List<String> path, ConfigEntry entry, Object fileValue) throws ConversionException Internal write-planning bridge that also takes the plain value the file holds atpath.- Parameters:
value- Java valuetype- declared typefile- configuration filepath- whole keysentry- annotation, or null for registry conversionfileValue- the plain value the file holds atpath, ornullwhen unknown- Returns:
- plain value and collected nested omissions
- Throws:
ConversionException- on conversion failure
-
ambiguousFileKeys
@Internal public List<List<String>> ambiguousFileKeys(Type type, Object fileValue, String file, List<String> path) File-key ambiguity scan: finds every typed map key that two or more of the file's own keys at one map level read back to (1:and'01':in aMap<Integer, String>), decided from the file's keys alone - no Java value is involved, so a key the module removed or never held still counts. It follows the same descent the writer uses (map entries by key text, list elements by index, only through declared map, collection and array types that the generic converter writes) and indexes each map level with the same helper the writer's binding uses, so the two never disagree. Only maps whose declared key type is neitherStringnorObjectare indexed; file keys that do not read as the key type are ignored. Reading a key is a probe and adds no failure anywhere.- Parameters:
type- declared type of the settingfileValue- the plain value the file holds atpathfile- configuration file, for locationpath- whole keys of the setting, for location- Returns:
- the located path of every ambiguous typed key, ending in its first spelling in file order; key paths only, never a value; empty when there is none
-
scanFileKeys
Descends where the writer descends: only through declared types the generic converter writes. -
scanFileList
Scans each list element by its index, where the declared type is an array or a collection. -
scanFileMap
Reports this map level's ambiguous typed keys, then scans every entry's value by its file key text. -
heldInSeveralSpellings
-
fromPlainResult
public <T> ConversionResult<T> fromPlainResult(Object plain, Type type, String file, List<String> path, ConfigEntry entry) throws ConversionException Selects an explicitly declared legacy parser before registry conversion.- Type Parameters:
T- result type- Parameters:
plain- document valuetype- declared typefile- configuration filepath- whole keysentry- annotation, or null for registry conversion- Returns:
- converted value and failures
- Throws:
ConversionException- on conversion failure
-
write
- Throws:
ConversionException
-
invokeWrite
private Object invokeWrite(ConfigConverter<Object> converter, Object value, ConverterRegistry.Context ctx) throws ConversionException - Throws:
ConversionException
-
read
- Throws:
ConversionException
-
invokeRead
private <T> T invokeRead(ConfigConverter<?> converter, Object plain, ConverterRegistry.Context ctx) throws ConversionException - Throws:
ConversionException
-
readSerializable
private Object readSerializable(Object plain, Class<? extends org.bukkit.configuration.serialization.ConfigurationSerializable> factory, ConverterRegistry.Context ctx) throws ConversionException - Throws:
ConversionException
-