org.javers.common.reflection.JaversFieldFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javers-core Show documentation
Show all versions of javers-core Show documentation
JaVers - object auditing and diff framework for Java
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);
}
}