package com.sys1yagi.fragmentcreator;

import com.sys1yagi.fragmentcreator.exception.InvalidParameterException;
import com.sys1yagi.fragmentcreator.exception.UnsupportedTypeException;

import java.lang.reflect.Field;

public abstract class FragmentCreator {

    public static void checkRequire(Object param, String paramName) {
        if (param == null) {
            throw new UnsupportedTypeException(paramName + "is required.");
        }
    }

    public static <T> void isValid(T param, Validator<T> validator) {
        if (!validator.isValid(param)) {
            //TODO rich message
            throw new InvalidParameterException(param.getClass().getName() + " is invalid.");
        }
    }

    public static <T> void set(T instance, String fieldName, Object value) {
        try {
            Class<?> clazz = instance.getClass();
            Field field = clazz.getField(fieldName);
            field.setAccessible(true);
            field.set(instance, value);
            field.setAccessible(false);
        } catch (Exception e) {
            //no op
        }
    }

    public static <T> Object get(T instance, String fieldName) {
        try {
            Class<?> clazz = instance.getClass();
            Field field = clazz.getField(fieldName);
            field.setAccessible(true);
            Object value = field.get(instance);
            field.setAccessible(false);
            return value;
        } catch (Exception e) {
            //no op
        }
        return null;
    }
}

@@ -182,41 +182,8 @@
 n;%0A%0A
-import java.lang.reflect.Field;%0A%0A
 publ
@@ -667,814 +667,7 @@
    %7D
-%0A%0A    public static %3CT%3E void set(T instance, String fieldName, Object value) %7B%0A        try %7B%0A            Class%3C?%3E clazz = instance.getClass();%0A            Field field = clazz.getField(fieldName);%0A            field.setAccessible(true);%0A            field.set(instance, value);%0A            field.setAccessible(false);%0A        %7D catch (Exception e) %7B%0A            //no op%0A        %7D%0A    %7D%0A%0A    public static %3CT%3E Object get(T instance, String fieldName) %7B%0A        try %7B%0A            Class%3C?%3E clazz = instance.getClass();%0A            Field field = clazz.getField(fieldName);%0A            field.setAccessible(true);%0A            Object value = field.get(instance);%0A            field.setAccessible(false);%0A            return value;%0A        %7D catch (Exception e) %7B%0A            //no op%0A        %7D%0A        return null;%0A    %7D
 %0A%7D%0A

Remove unused code.