Makes comments apply when inside nested classes of nested classes.

This commit is contained in:
adrianoy
2021-07-25 22:20:35 -03:00
parent 48f5962f57
commit 1fe4d53565
4 changed files with 120 additions and 5 deletions
+10
View File
@@ -188,7 +188,9 @@ afterEvaluate {
sourceSets { sourceSets {
testmod { testmod {
compileClasspath += main.output
compileClasspath += main.compileClasspath compileClasspath += main.compileClasspath
runtimeClasspath += main.output
runtimeClasspath += main.runtimeClasspath runtimeClasspath += main.runtimeClasspath
} }
test { test {
@@ -239,5 +241,13 @@ publishing {
} }
} }
} }
//todo: remove before pr'ing
import net.fabricmc.loom.task.RunClientTask
task runTestMod(type: RunClientTask) {
classpath = configurations.runtimeClasspath
classpath sourceSets.main.output
classpath sourceSets.testmod.output
}
tasks.publish.dependsOn build //stupid fix for maven/loom not publishing the main artifact tasks.publish.dependsOn build //stupid fix for maven/loom not publishing the main artifact
@@ -23,7 +23,12 @@ import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class OmegaConfig { public class OmegaConfig {
@@ -109,10 +114,9 @@ public class OmegaConfig {
addFieldComments(field, keyToComments); addFieldComments(field, keyToComments);
} }
// get inner-class fields // "flattens" all the inner classes of the Config class into a single list
// TODO: recursively get inner classes? for (Class<?> clazz : flatten(configClass.getDeclaredClasses())) {
for (Class<?> innerClass : configClass.getDeclaredClasses()) { for (Field field : clazz.getDeclaredFields()) {
for (Field field : innerClass.getDeclaredFields()) {
addFieldComments(field, keyToComments); addFieldComments(field, keyToComments);
} }
} }
@@ -154,6 +158,32 @@ public class OmegaConfig {
} }
} }
private static List<Class<?>> flatten(Class<?>[] array) {
List<Class<?>> list = new ArrayList<>();
if (array.length <= 0) {
return list;
}
for (Class<?> clazz : array) {
populateRecursively(list, clazz);
}
return list;
}
private static void populateRecursively(List<Class<?>> list, Class<?> aClass) {
list.add(aClass);
Class<?>[] classes = aClass.getDeclaredClasses();
if (classes.length != 0) {
for (Class<?> clazz : classes) {
populateRecursively(list, clazz);
}
}
}
private static void addFieldComments(Field field, Map<String, String> keyToComments) { private static void addFieldComments(Field field, Map<String, String> keyToComments) {
String fieldName = field.getName(); String fieldName = field.getName();
Annotation[] annotations = field.getDeclaredAnnotations(); Annotation[] annotations = field.getDeclaredAnnotations();
@@ -2,6 +2,7 @@ package draylar.omegatest;
import draylar.omegaconfig.OmegaConfig; import draylar.omegaconfig.OmegaConfig;
import draylar.omegatest.config.ClassConfigTest; import draylar.omegatest.config.ClassConfigTest;
import draylar.omegatest.config.CommentedNestedClassConfig;
import draylar.omegatest.config.NestedConfigTest; import draylar.omegatest.config.NestedConfigTest;
import draylar.omegatest.config.SimpleConfigTest; import draylar.omegatest.config.SimpleConfigTest;
import draylar.omegatest.config.StructuresConfigTest; import draylar.omegatest.config.StructuresConfigTest;
@@ -13,6 +14,7 @@ public class OmegaTestMain implements ModInitializer {
public static final StructuresConfigTest MO_CONFIG = OmegaConfig.register(StructuresConfigTest.class); public static final StructuresConfigTest MO_CONFIG = OmegaConfig.register(StructuresConfigTest.class);
public static final NestedConfigTest NESTED = OmegaConfig.register(NestedConfigTest.class); public static final NestedConfigTest NESTED = OmegaConfig.register(NestedConfigTest.class);
public static final ClassConfigTest CLASS = OmegaConfig.register(ClassConfigTest.class); public static final ClassConfigTest CLASS = OmegaConfig.register(ClassConfigTest.class);
public static final CommentedNestedClassConfig COMMENTED_NESTED_CLASS = OmegaConfig.register(CommentedNestedClassConfig.class);
@Override @Override
public void onInitialize() { public void onInitialize() {
@@ -0,0 +1,73 @@
package draylar.omegatest.config;
import draylar.omegaconfig.api.Comment;
import draylar.omegaconfig.api.Config;
public class CommentedNestedClassConfig implements Config {
@Comment("Very nested test")
public First first = new First();
@Comment("True")
public boolean test = false;
@Comment("First-Level")
public VeryNested veryNested = new VeryNested();
public static class First {
@Comment("Cucumbers")
public boolean cucumbers = true;
@Comment("InnerFirst")
public InnerFirst innerFirst = new InnerFirst();
@Comment("InnerSecond")
public InnerSecond innerSecond = new InnerSecond();
public static class InnerFirst {
@Comment("Number of Tomatoes")
public int numberOfTomatoes = 10;
}
public static class InnerSecond {
@Comment("Inner Second First")
public InnerSecondFirst innerSecondFirst = new InnerSecondFirst();
public static class InnerSecondFirst {
@Comment("Olive Oil")
public String oliveOil = "oliveOil";
}
}
}
public static class VeryNested {
@Comment("Second-Level")
public Very very = new Very();
public static class Very {
@Comment("Third-Level")
public VeryVery veryVery = new VeryVery();
public static class VeryVery {
@Comment("Forth-Level")
public VeryVeryVery veryVeryVery = new VeryVeryVery();
public static class VeryVeryVery {
@Comment("Fifth-Level")
public VeryVeryVeryVery veryVeryVeryVery = new VeryVeryVeryVery();
public static class VeryVeryVeryVery {
@Comment("Sixth-Level")
public String last = "last";
}
}
}
}
}
@Override
public String getName() {
return "commented-inner-classes";
}
@Override
public String getExtension() {
return "json5";
}
}