Skip to content

Commit ab96873

Browse files
committed
Replace SettingsHolderClassValidator#getAllFields with type resolver util method
1 parent 7f24ae9 commit ab96873

File tree

1 file changed

+2
-26
lines changed

1 file changed

+2
-26
lines changed

src/main/java/ch/jalu/configme/utils/SettingsHolderClassValidator.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import ch.jalu.configme.resource.PropertyReader;
99
import ch.jalu.configme.resource.PropertyResource;
1010
import ch.jalu.typeresolver.EnumUtils;
11+
import ch.jalu.typeresolver.reflect.FieldUtils;
1112
import org.jetbrains.annotations.NotNull;
1213
import org.jetbrains.annotations.Nullable;
1314

@@ -20,7 +21,6 @@
2021
import java.util.Map;
2122
import java.util.function.Predicate;
2223
import java.util.stream.Collectors;
23-
import java.util.stream.Stream;
2424

2525
/**
2626
* Validates various characteristics of the property implementations of SettingsHolder classes for consistency.
@@ -105,7 +105,7 @@ public void validateAllPropertiesAreConstants(@NotNull Iterable<Class<? extends
105105
List<String> invalidFields = new ArrayList<>();
106106

107107
for (Class<? extends SettingsHolder> clazz : settingHolders) {
108-
List<String> invalidFieldsForClazz = getAllFields(clazz)
108+
List<String> invalidFieldsForClazz = FieldUtils.getAllFields(clazz, false)
109109
.filter(field -> Property.class.isAssignableFrom(field.getType()))
110110
.filter(field -> !isValidConstantField(field))
111111
.map(field -> field.getDeclaringClass().getSimpleName() + "#" + field.getName())
@@ -314,28 +314,4 @@ protected boolean hasValidConstructorSetup(@NotNull Class<? extends SettingsHold
314314
&& constructors[0].getParameterCount() == 0
315315
&& Modifier.isPrivate(constructors[0].getModifiers());
316316
}
317-
318-
/**
319-
* Returns all fields of the class, including all fields of parent classes, recursively.
320-
*
321-
* @param clazz the class whose fields should be retrieved
322-
* @return all fields of the class, including its parents
323-
*/
324-
protected @NotNull Stream<Field> getAllFields(@NotNull Class<?> clazz) {
325-
// Shortcut: Class does not inherit from another class, so just go through its fields
326-
if (Object.class.equals(clazz.getSuperclass())) {
327-
return Arrays.stream(clazz.getDeclaredFields());
328-
}
329-
330-
// Collect all classes incl. parents
331-
Class<?> currentClass = clazz;
332-
List<Class<?>> classes = new ArrayList<>();
333-
while (currentClass != null && !currentClass.equals(Object.class)) {
334-
classes.add(currentClass);
335-
currentClass = currentClass.getSuperclass();
336-
}
337-
338-
// Go through all fields incl. parents
339-
return classes.stream().flatMap(clz -> Arrays.stream(clz.getDeclaredFields()));
340-
}
341317
}

0 commit comments

Comments
 (0)