Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigEntry.Gui.CollapsibleObject does not include fields in super classes #275

Open
rikka0w0 opened this issue Jul 28, 2024 · 0 comments
Open

Comments

@rikka0w0
Copy link

As the title suggests. It is inconvenient when handling a large set of similar options and requires a lot of duplication and hard coding.

I found a solution. In DefaultGuiProviders.java:

    private static List<AbstractConfigListEntry> getChildren(String i18n, Class<?> fieldType, Object iConfig, Object iDefaults, GuiRegistryAccess guiProvider) {
-        return Arrays.stream(fieldType.getDeclaredFields())
+       return traverseFields(fieldType, true).stream()

where traverseFields is a new helper function:

	private static List<Field> traverseFields(Class<?> fieldType, boolean includeSuper) {
		List<Field> result = new LinkedList<>();
		Class<?> cls = fieldType;
		while (cls != null && !cls.equals(Object.class)) {
			result.addAll(Arrays.asList(cls.getDeclaredFields()));

			if (!includeSuper) {
				break;
			}

			cls = cls.getSuperclass();
		}
		return result;
	}

We could introduce another option in the CollapsibleObject annotation to specify whether we include the fields in its super class or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant