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

org.javers.common.reflection.JaversFieldFactory Maven / Gradle / Ivy

There is a newer version: 7.6.1
Show newest version
package org.javers.common.reflection;

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

/**
 * @author bartosz walacik
 */
class JaversFieldFactory {

    private final Class methodSource;

    public JaversFieldFactory(Class methodSource) {
        this.methodSource = methodSource;
    }

    public List getAllFields(){
        List fields = new ArrayList<>();
        TypeResolvingContext context = new TypeResolvingContext();

        Class clazz = methodSource;
        while (clazz != null && clazz != Object.class)  {
            context.addTypeSubstitutions(clazz);

            for (Field f : clazz.getDeclaredFields()){
                fields.add(createJField(f,context));
            }

            clazz = clazz.getSuperclass();
        }

        return fields;
    }

    private JaversField createJField(Field rawField, TypeResolvingContext context){
        Type actualType = context.getSubstitution(rawField.getGenericType());
        return new JaversField(rawField, actualType);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy