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

Half-recursive getProperties #992

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -750,28 +750,30 @@ private static ConfigMappingInterface[] getSuperTypes(Class<?>[] interfaces, int
}

static Property[] getProperties(Method[] methods, int si, int ti) {
if (si == methods.length) {
if (ti == 0) {
return NO_PROPERTIES;
for (int i = si; i < methods.length; i++) {
Method method = methods[i];
int mods = method.getModifiers();
if (!Modifier.isPublic(mods) || Modifier.isStatic(mods) || !Modifier.isAbstract(mods)) {
// no need for recursive calls here, which are costy in interpreted mode!
continue;
}
if (method.getParameterCount() > 0) {
throw new IllegalArgumentException("Configuration methods cannot accept parameters");
}
if (method.getReturnType() == void.class) {
throw new IllegalArgumentException("Void config methods are not allowed");
}
Property p = getPropertyDef(method, method.getAnnotatedReturnType());
final Property[] array;
if (i + 1 == methods.length) {
array = new Property[ti + 1];
} else {
return new Property[ti];
array = getProperties(methods, i + 1, ti + 1);
}
array[ti] = p;
return array;
}
Method method = methods[si];
int mods = method.getModifiers();
if (!Modifier.isPublic(mods) || Modifier.isStatic(mods) || !Modifier.isAbstract(mods)) {
return getProperties(methods, si + 1, ti);
}
if (method.getParameterCount() > 0) {
throw new IllegalArgumentException("Configuration methods cannot accept parameters");
}
if (method.getReturnType() == void.class) {
throw new IllegalArgumentException("Void config methods are not allowed");
}
Property p = getPropertyDef(method, method.getAnnotatedReturnType());
Property[] array = getProperties(methods, si + 1, ti + 1);
array[ti] = p;
return array;
return ti > 0 ? new Property[ti] : NO_PROPERTIES;
}

private static Property getPropertyDef(Method method, AnnotatedType type) {
Expand Down