From 1d68bb4827f7373b060ff3605a8d99a092e2f7eb Mon Sep 17 00:00:00 2001 From: "yrsegal@gmail.com" Date: Wed, 7 Aug 2024 15:21:37 -0400 Subject: [PATCH] add ability to have a comment on the general section of a config --- .../java/org/violetmoon/zeta/config/Config.java | 6 ++++++ .../zeta/config/ConfigObjectMapper.java | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/violetmoon/zeta/config/Config.java b/src/main/java/org/violetmoon/zeta/config/Config.java index 7957f79..0351f2a 100644 --- a/src/main/java/org/violetmoon/zeta/config/Config.java +++ b/src/main/java/org/violetmoon/zeta/config/Config.java @@ -38,4 +38,10 @@ boolean exclusive() default false; } + @Target(ElementType.TYPE) + @Retention(RetentionPolicy.RUNTIME) + @interface RootComment { + String value(); + } + } diff --git a/src/main/java/org/violetmoon/zeta/config/ConfigObjectMapper.java b/src/main/java/org/violetmoon/zeta/config/ConfigObjectMapper.java index 14d844f..19ea311 100644 --- a/src/main/java/org/violetmoon/zeta/config/ConfigObjectMapper.java +++ b/src/main/java/org/violetmoon/zeta/config/ConfigObjectMapper.java @@ -1,5 +1,10 @@ package org.violetmoon.zeta.config; +import org.apache.commons.lang3.text.WordUtils; +import org.jetbrains.annotations.Nullable; +import org.violetmoon.zeta.config.type.IConfigType; +import org.violetmoon.zeta.module.ZetaModule; + import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -12,11 +17,6 @@ import java.util.function.Consumer; import java.util.function.Predicate; -import org.apache.commons.lang3.text.WordUtils; -import org.jetbrains.annotations.Nullable; -import org.violetmoon.zeta.config.type.IConfigType; -import org.violetmoon.zeta.module.ZetaModule; - public class ConfigObjectMapper { public static List walkModuleFields(Class clazz) { List list = new ArrayList<>(); @@ -58,6 +58,11 @@ public static void readInto(SectionDefinition.Builder sect, Object obj, List> databindings, ConfigFlagManager cfm) { + Config.RootComment rootComment = obj.getClass().getAnnotation(Config.RootComment.class); + if (rootComment != null) { + sect.comment(List.of(rootComment.value().split("\n"))); + } + for(Field field : walkModuleFields(obj.getClass())) { Config config = field.getAnnotation(Config.class);