aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2023-11-17 16:40:15 +0000
committerisXander <xandersmith2008@gmail.com>2023-11-28 20:55:19 +0000
commit5c2201d85a727e1d68ab64b1abdc3fd8518c816b (patch)
tree0f8cf0a74c2fed61b8c1c2823a2bb936ec75b682
parentb498a6b2d48d7d564150f55ab6e5fb2c7ce301de (diff)
downloadYetAnotherConfigLib-5c2201d85a727e1d68ab64b1abdc3fd8518c816b.tar.gz
YetAnotherConfigLib-5c2201d85a727e1d68ab64b1abdc3fd8518c816b.tar.bz2
YetAnotherConfigLib-5c2201d85a727e1d68ab64b1abdc3fd8518c816b.zip
Warn when using old @ConfigEntry annotation when using config v2
-rw-r--r--common/src/main/java/dev/isxander/yacl3/config/v2/impl/ConfigClassHandlerImpl.java26
-rw-r--r--common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java2
2 files changed, 24 insertions, 4 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/ConfigClassHandlerImpl.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/ConfigClassHandlerImpl.java
index c363a7d..813b3ab 100644
--- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/ConfigClassHandlerImpl.java
+++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/ConfigClassHandlerImpl.java
@@ -1,6 +1,7 @@
package dev.isxander.yacl3.config.v2.impl;
import dev.isxander.yacl3.api.*;
+import dev.isxander.yacl3.config.ConfigEntry;
import dev.isxander.yacl3.config.v2.api.*;
import dev.isxander.yacl3.config.v2.api.autogen.AutoGen;
import dev.isxander.yacl3.config.v2.api.autogen.OptionAccess;
@@ -46,12 +47,24 @@ public class ConfigClassHandlerImpl<T> implements ConfigClassHandler<T> {
this.instance = createNewObject();
this.defaults = createNewObject();
- this.fields = Arrays.stream(configClass.getDeclaredFields())
+ detectOldAnnotation(configClass.getDeclaredFields());
+
+ this.fields = discoverFields();
+ this.serializer = serializerFactory.apply(this);
+ }
+
+ private ConfigFieldImpl<?>[] discoverFields() {
+ return Arrays.stream(configClass.getDeclaredFields())
.peek(field -> field.setAccessible(true))
.filter(field -> field.isAnnotationPresent(SerialEntry.class) || field.isAnnotationPresent(AutoGen.class))
- .map(field -> new ConfigFieldImpl<>(new ReflectionFieldAccess<>(field, instance), new ReflectionFieldAccess<>(field, defaults), this, field.getAnnotation(SerialEntry.class), field.getAnnotation(AutoGen.class)))
+ .map(field -> new ConfigFieldImpl<>(
+ new ReflectionFieldAccess<>(field, instance),
+ new ReflectionFieldAccess<>(field, defaults),
+ this,
+ field.getAnnotation(SerialEntry.class),
+ field.getAnnotation(AutoGen.class)
+ ))
.toArray(ConfigFieldImpl[]::new);
- this.serializer = serializerFactory.apply(this);
}
@Override
@@ -212,6 +225,13 @@ public class ConfigClassHandlerImpl<T> implements ConfigClassHandler<T> {
}
}
+ private void detectOldAnnotation(Field[] fields) {
+ boolean hasOldConfigEntry = Arrays.stream(fields)
+ .anyMatch(field -> field.isAnnotationPresent(ConfigEntry.class));
+
+ Validate.isTrue(!hasOldConfigEntry, "At least one field in %s is still annotated with the deprecated @ConfigEntry annotation. This is incorrect. Use @SerialEntry.".formatted(configClass.getName()));
+ }
+
public static class BuilderImpl<T> implements Builder<T> {
private final Class<T> configClass;
private ResourceLocation id;
diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java
index a60bcb1..49f2a47 100644
--- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java
+++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/serializer/GsonConfigSerializer.java
@@ -1,7 +1,6 @@
package dev.isxander.yacl3.config.v2.impl.serializer;
import com.google.gson.*;
-import dev.isxander.yacl3.config.GsonConfigInstance;
import dev.isxander.yacl3.config.v2.api.*;
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
import dev.isxander.yacl3.gui.utils.ItemRegistryHelper;
@@ -168,6 +167,7 @@ public class GsonConfigSerializer<T> extends ConfigSerializer<T> {
@Override
@Deprecated
+ @SuppressWarnings("deprecation")
public void load() {
YACLConstants.LOGGER.warn("Calling ConfigSerializer#load() directly is deprecated. Please use ConfigClassHandler#load() instead.");
config.load();