de.thksystems.util.reflection.ReflectionUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tkscommons Show documentation
Show all versions of tkscommons Show documentation
Commons for lang, crypto, dom, text, csv, reflection, parsing, xtreams...
/*
* tksCommons
*
* Author : Thomas Kuhlmann (ThK-Systems, http://www.thk-systems.de) License : LGPL (https://www.gnu.org/licenses/lgpl.html)
*/
package de.thksystems.util.reflection;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
/**
* Reflection-Helper.
*/
public final class ReflectionUtils {
private ReflectionUtils() {
}
/**
* Gets all fields from a class including the fields from all its super-classes.
*/
public static List getAllFields(Class> type) {
List fieldList = new ArrayList<>();
getAllFields(fieldList, type);
return fieldList;
}
private static List getAllFields(List fields, Class> type) {
for (Field field : type.getDeclaredFields()) {
fields.add(field);
}
if (type.getSuperclass() != null) {
fields = getAllFields(fields, type.getSuperclass());
}
return fields;
}
}