All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.lumongo.util.AnnotationUtil Maven / Gradle / Ivy

There is a newer version: 0.52
Show newest version
package org.lumongo.util;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

public class AnnotationUtil {
	public static List getNonStaticFields(final Class clazz, boolean deep) {
		List fields = new ArrayList<>();
		for (Field f : clazz.getDeclaredFields()) {
			if (!Modifier.isStatic(f.getModifiers())) {
				fields.add(f);
			}
		}
		
		if (deep) {
			Class parent = clazz.getSuperclass();
			while ((parent != null) && (parent != Object.class)) {
				for (Field f : parent.getDeclaredFields()) {
					if (!Modifier.isStatic(f.getModifiers())) {
						fields.add(f);
					}
				}
				
				parent = parent.getSuperclass();
			}
		}
		
		return fields;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy