فهرست منبع

Code improvements

Lortseam 4 سال پیش
والد
کامیت
fa8ab7106e

+ 11 - 10
lib/src/main/java/me/lortseam/completeconfig/data/Entry.java

@@ -7,15 +7,15 @@ import lombok.extern.log4j.Log4j2;
 import me.lortseam.completeconfig.CompleteConfig;
 import me.lortseam.completeconfig.api.ConfigContainer;
 import me.lortseam.completeconfig.api.ConfigEntry;
+import me.lortseam.completeconfig.data.client.TooltipSupplier;
 import me.lortseam.completeconfig.data.client.Translatable;
-import me.lortseam.completeconfig.data.transform.Transformation;
-import me.lortseam.completeconfig.data.transform.Transformer;
 import me.lortseam.completeconfig.data.structure.DataPart;
 import me.lortseam.completeconfig.data.structure.Identifiable;
-import me.lortseam.completeconfig.data.client.TooltipSupplier;
-import me.lortseam.completeconfig.text.TranslationKey;
+import me.lortseam.completeconfig.data.transform.Transformation;
+import me.lortseam.completeconfig.data.transform.Transformer;
 import me.lortseam.completeconfig.exception.IllegalAnnotationParameterException;
 import me.lortseam.completeconfig.extensions.CompleteConfigExtension;
+import me.lortseam.completeconfig.text.TranslationKey;
 import me.lortseam.completeconfig.util.ReflectionUtils;
 import net.fabricmc.api.EnvType;
 import net.fabricmc.api.Environment;
@@ -53,8 +53,6 @@ public class Entry<T> implements DataPart, Identifiable, Translatable, TooltipSu
 
     protected final EntryOrigin origin;
     @Getter
-    private final Type type;
-    @Getter
     private final Class<T> typeClass;
     @Getter
     private final String id;
@@ -76,8 +74,7 @@ public class Entry<T> implements DataPart, Identifiable, Translatable, TooltipSu
         if (!origin.getField().isAccessible()) {
             origin.getField().setAccessible(true);
         }
-        type = origin.getType();
-        typeClass = (Class<T>) ReflectionUtils.getTypeClass(type);
+        typeClass = (Class<T>) ReflectionUtils.getTypeClass(getType());
         this.valueModifier = valueModifier;
         defaultValue = getValue();
         Optional<ConfigEntry> annotation = origin.getOptionalAnnotation(ConfigEntry.class);
@@ -90,6 +87,10 @@ public class Entry<T> implements DataPart, Identifiable, Translatable, TooltipSu
         this(origin, null);
     }
 
+    public Type getType() {
+        return origin.getType();
+    }
+
     public T getValue() {
         if (update()) {
             return getValue();
@@ -171,7 +172,7 @@ public class Entry<T> implements DataPart, Identifiable, Translatable, TooltipSu
     @Override
     public void apply(CommentedConfigurationNode node) {
         try {
-            setValue((T) node.get(type));
+            setValue((T) node.get(getType()));
         } catch (SerializationException e) {
             logger.error("Failed to apply value to entry", e);
         }
@@ -180,7 +181,7 @@ public class Entry<T> implements DataPart, Identifiable, Translatable, TooltipSu
     @Override
     public void fetch(CommentedConfigurationNode node) {
         try {
-            node.set(type, getValue());
+            node.set(getType(), getValue());
             if (comment != null) {
                 node.comment(comment);
             }

+ 8 - 5
lib/src/main/java/me/lortseam/completeconfig/data/EntryOrigin.java

@@ -3,7 +3,6 @@ package me.lortseam.completeconfig.data;
 import lombok.AccessLevel;
 import lombok.EqualsAndHashCode;
 import lombok.Getter;
-import lombok.RequiredArgsConstructor;
 import me.lortseam.completeconfig.api.ConfigContainer;
 import me.lortseam.completeconfig.util.ReflectionUtils;
 
@@ -12,7 +11,6 @@ import java.lang.reflect.Field;
 import java.lang.reflect.Type;
 import java.util.Optional;
 
-@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
 @EqualsAndHashCode(onlyExplicitlyIncluded = true)
 public final class EntryOrigin {
 
@@ -20,13 +18,18 @@ public final class EntryOrigin {
     private final BaseCollection parent;
     @Getter
     @EqualsAndHashCode.Include
-    protected final Field field;
+    private final Field field;
+    @Getter
+    private final Type type;
     @Getter
     @EqualsAndHashCode.Include
     private final ConfigContainer object;
 
-    public Type getType() {
-        return ReflectionUtils.getFieldType(field);
+    EntryOrigin(BaseCollection parent, Field field, ConfigContainer object) {
+        this.parent = parent;
+        this.field = field;
+        type = ReflectionUtils.getFieldType(field);
+        this.object = object;
     }
 
     public <A extends Annotation> A getAnnotation(Class<A> annotationType) {