com.aventstack.extentreports.markuputils.util.ReflectionUtil Maven / Gradle / Ivy
package com.aventstack.extentreports.markuputils.util;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class ReflectionUtil {
public static List getFieldsIgnoringAnnotation(Class> clazz,
Class extends Annotation> skippingAnnotationClazz) {
if (clazz == null)
return Collections.emptyList();
List fields = new ArrayList<>(
getFieldsIgnoringAnnotation(clazz.getSuperclass(), skippingAnnotationClazz));
List filteredList = Arrays.stream(clazz.getDeclaredFields())
.filter(x -> !x.isAnnotationPresent(skippingAnnotationClazz))
.collect(Collectors.toList());
fields.addAll(filteredList);
return fields;
}
public static List getAnnotatedFields(Class> clazz,
Class extends Annotation> annotationClazz) {
if (clazz == null)
return Collections.emptyList();
List fields = new ArrayList<>(getAnnotatedFields(clazz.getSuperclass(), annotationClazz));
List filteredList = Arrays.stream(clazz.getDeclaredFields())
.filter(x -> x.isAnnotationPresent(annotationClazz))
.collect(Collectors.toList());
fields.addAll(filteredList);
return fields;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy