Skip to content

Commit

Permalink
add ability to have a comment on the general section of a config
Browse files Browse the repository at this point in the history
  • Loading branch information
yrsegal committed Aug 7, 2024
1 parent 0090b77 commit 1d68bb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/violetmoon/zeta/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@
boolean exclusive() default false;
}

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface RootComment {
String value();
}

}
15 changes: 10 additions & 5 deletions src/main/java/org/violetmoon/zeta/config/ConfigObjectMapper.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Field> walkModuleFields(Class<?> clazz) {
List<Field> list = new ArrayList<>();
Expand Down Expand Up @@ -58,6 +58,11 @@ public static void readInto(SectionDefinition.Builder sect, Object obj, List<Con
}

public static void readInto(SectionDefinition.Builder sect, Object obj, @Nullable ZetaModule enclosingModule, List<Consumer<IZetaConfigInternals>> 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);

Expand Down

0 comments on commit 1d68bb4

Please sign in to comment.