net.thucydides.core.annotations.AnnotatedFields Maven / Gradle / Ivy
package net.thucydides.core.annotations;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* Find the annotated fields in a given class.
* Used as a utility class for the higher-level annotation processing.
* Typical use:
*
*
* for (Field field : AnnotatedFields.of(someClass).allFields()) {
* ...
* }
*
*
*/
public class AnnotatedFields {
private final Class> clazz;
public static AnnotatedFields of(final Class> testClass) {
return new AnnotatedFields(testClass);
}
private AnnotatedFields(Class> clazz) {
this.clazz = clazz;
}
public Set allFields() {
Set fields = new HashSet();
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
fields.addAll(Arrays.asList(clazz.getFields()));
if (clazz != Object.class) {
fields.addAll(AnnotatedFields.of(clazz.getSuperclass()).allFields());
}
return fields;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy