Class PropertyResolver
java.lang.Object
net.darkhax.pricklemc.common.api.config.PropertyResolver
Handles properties and settings related to resolving properties and JSON values.
-
Constructor Summary
ConstructorsConstructorDescriptionPropertyResolver(com.google.gson.Gson gson, org.slf4j.Logger logger, List<IPropertyAdapter<?>> propertyAdapters, ICommentResolver commentResolver) -
Method Summary
Modifier and TypeMethodDescriptioncom.google.gson.Gsongson()Gets a configured GSON instance that should be used when serializing properties.org.slf4j.Loggerlogger()Gets a logger instance that can be used when serializing properties.@Nullable ICommentAttempts to resolve a comment for a config property.toProperty(Field field, Object parent, Value cfgValue) Maps a Java field to a config property.
-
Constructor Details
-
PropertyResolver
public PropertyResolver(com.google.gson.Gson gson, org.slf4j.Logger logger, List<IPropertyAdapter<?>> propertyAdapters, ICommentResolver commentResolver)
-
-
Method Details
-
gson
public com.google.gson.Gson gson()Gets a configured GSON instance that should be used when serializing properties.- Returns:
- The GSON instance to use for serializing.
-
toComment
@Nullable public @Nullable IComment toComment(Field field, Object value, Value valueMeta) throws IOException Attempts to resolve a comment for a config property.- Parameters:
field- The field to resolve.value- The value of the field.valueMeta- The Value annotation that was on the field.- Returns:
- The comment that was resolved. If null no comment was specified.
- Throws:
IOException- An IOException may be raised when the resolver encounters a fatal error.
-
logger
public org.slf4j.Logger logger()Gets a logger instance that can be used when serializing properties.- Returns:
- The logger used for errors and warnings related to the config file.
-
toProperty
public IConfigProperty<?> toProperty(Field field, Object parent, Value cfgValue) throws IOException, IllegalAccessException Maps a Java field to a config property. This process will first look for theAdapterannotation on the field, then try the registered property adapters, then try the sub-object fallback for config objects, and lastly default to a normal Gson object.- Parameters:
field- The field to map.parent- The object that holds the field.cfgValue- The Value annotation that was on the field.- Returns:
- The mapped config property.
- Throws:
IOException- An IOException may be raised when a property adapter encounters a fatal error.IllegalAccessException- This exception may be raised if the field is not accessible.
-