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

com.aventstack.extentreports.markuputils.util.ReflectionUtil Maven / Gradle / Ivy

There is a newer version: 5.1.2
Show newest version
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 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 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