|
8 | 8 | import ch.jalu.configme.resource.PropertyReader; |
9 | 9 | import ch.jalu.configme.resource.PropertyResource; |
10 | 10 | import ch.jalu.typeresolver.EnumUtils; |
| 11 | +import ch.jalu.typeresolver.reflect.FieldUtils; |
11 | 12 | import org.jetbrains.annotations.NotNull; |
12 | 13 | import org.jetbrains.annotations.Nullable; |
13 | 14 |
|
|
20 | 21 | import java.util.Map; |
21 | 22 | import java.util.function.Predicate; |
22 | 23 | import java.util.stream.Collectors; |
23 | | -import java.util.stream.Stream; |
24 | 24 |
|
25 | 25 | /** |
26 | 26 | * Validates various characteristics of the property implementations of SettingsHolder classes for consistency. |
@@ -105,7 +105,7 @@ public void validateAllPropertiesAreConstants(@NotNull Iterable<Class<? extends |
105 | 105 | List<String> invalidFields = new ArrayList<>(); |
106 | 106 |
|
107 | 107 | for (Class<? extends SettingsHolder> clazz : settingHolders) { |
108 | | - List<String> invalidFieldsForClazz = getAllFields(clazz) |
| 108 | + List<String> invalidFieldsForClazz = FieldUtils.getAllFields(clazz, false) |
109 | 109 | .filter(field -> Property.class.isAssignableFrom(field.getType())) |
110 | 110 | .filter(field -> !isValidConstantField(field)) |
111 | 111 | .map(field -> field.getDeclaringClass().getSimpleName() + "#" + field.getName()) |
@@ -314,28 +314,4 @@ protected boolean hasValidConstructorSetup(@NotNull Class<? extends SettingsHold |
314 | 314 | && constructors[0].getParameterCount() == 0 |
315 | 315 | && Modifier.isPrivate(constructors[0].getModifiers()); |
316 | 316 | } |
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 | | - } |
341 | 317 | } |
0 commit comments