package com.exmertec.dummie.generator;

import com.exmertec.dummie.generator.data.DataGenerator;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.PropertyUtilsBean;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class Inflater {
    private static void inflateFields(Object instance, DataGenerator dataGenerator, Class<?> classType) throws
        IllegalAccessException,
        InvocationTargetException {
        Field[] fields = classType.getDeclaredFields();
        PropertyUtilsBean propertyUtils = BeanUtilsBean.getInstance().getPropertyUtils();

        for (Field field : fields) {
            if (!propertyUtils.isWriteable(instance, field.getName())) {
                continue;
            }

            Object value = dataGenerator.getData(field);
            BeanUtils.setProperty(instance, field.getName(), value);
        }
    }

    public static void inflateInstance(Object instance, DataGenerator cache, Class<?> type) throws
        InvocationTargetException,
        IllegalAccessException {
        if (type != null) {
            inflateFields(instance, cache, type);
            inflateInstance(instance, cache, type.getSuperclass());
        }
    }
}

@@ -367,24 +367,28 @@
 ivate static
+ %3CT%3E
  void inflat
@@ -395,22 +395,17 @@
 eFields(
-Object
+T
  instanc
@@ -442,17 +442,17 @@
 , Class%3C
-?
+T
 %3E classT
@@ -494,24 +494,16 @@
 ception,
-%0A       
  Invocat
@@ -981,16 +981,20 @@
 c static
+ %3CT%3E
  void in
@@ -1007,22 +1007,17 @@
 nstance(
-Object
+T
  instanc
@@ -1050,9 +1050,9 @@
 ass%3C
-?
+T
 %3E ty
@@ -1096,24 +1096,16 @@
 ception,
-%0A       
  Illegal

use template for inflater