Generates a setter that set the value by directly accessing the class field.
@param field The reflection field object.
165661
private void directSetter(Field field) {
    GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC,
                                               getMethod(void.class, "set", Object.class, Object.class),
                                               setterSignature(), new Type[0], classWriter);
    // Simply access by field
    // ((classType)object).fieldName = (valueType)value;
    mg.loadArg(0);
    mg.checkCast(Type.getType(field.getDeclaringClass()));
    mg.loadArg(1);
    if (field.getType().isPrimitive()) {
      mg.unbox(Type.getType(field.getType()));
    } else {
      mg.checkCast(Type.getType(field.getType()));
    }
    mg.putField(Type.getType(field.getDeclaringClass()), field.getName(), Type.getType(field.getType()));
    mg.returnValue();
    mg.endMethod();
  }
59159
public void setFieldValue(Object fieldValue) {
		ReflectionUtils.callSetter(parentWrapper.getItem(), field.getName(), fieldValue);
	}
475552
private static Object generateValue(Field field) {
    Class<?> rawType = field.getType();

    //TODO Objects other than Lists might need parametrized types.
    if (List.class.isAssignableFrom(rawType)) {
      ParameterizedType genericType = (ParameterizedType) field.getGenericType();
      return createListObject(genericType);
    }

    return generateValue(rawType);
  }
482438
public static void write(ObjectOutput out, java.lang.reflect.Field field) throws IOException {
        if (field == null) {
            ClassRef.write(out, null);
        } else {
            ClassRef.write(out, field.getDeclaringClass());
            out.writeUTF(field.getName());
        }
    }
702416
private void primitiveGetter(Field field) {
    String typeName = field.getType().getName();
    String methodName = String.format("get%c%s", Character.toUpperCase(typeName.charAt(0)), typeName.substring(1));

    GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, getMethod(field.getType(), methodName, Object.class),
                                               null, new Type[0], classWriter);
    if (isPrivate) {
      // get the value using the generic Object get(Object) method and unbox the value
      mg.loadThis();
      mg.loadArg(0);
      mg.invokeVirtual(Type.getObjectType(className), getMethod(Object.class, "get", Object.class));
      mg.unbox(Type.getType(field.getType()));
    } else {
      // Simply access the field.
      mg.loadArg(0);
      mg.checkCast(Type.getType(field.getDeclaringClass()));
      mg.getField(Type.getType(field.getDeclaringClass()), field.getName(), Type.getType(field.getType()));
    }
    mg.returnValue();
    mg.endMethod();
  }
385560
public void setValueFor(Field target, Object value) {
        if(value == null && target.getType().isPrimitive()) {
            throw new ND4JIllegalStateException("Unable to set primitive field " + target + " of type " + target.getClass()
                    + " using null value!");
        }

        if(value != null) {
            value = ensureProperType(target, value);
        }

        if(isConfigProperties()){
            String propertyName = configFieldName();
            if(propertyName == null)
                propertyName = "config";
            Field f = null;
            Class<?> currClass = getClass();
            try{
                f = currClass.getDeclaredField(propertyName);
            } catch (NoSuchFieldException e){
                //OK, try superclass
            }
            while(f == null && currClass.getSuperclass() != null){
                currClass = currClass.getSuperclass();
                try{
                    f = currClass.getDeclaredField(propertyName);
                } catch (NoSuchFieldException e){
                    //OK, try superclass
                }
            }

            if(f == null){
                throw new IllegalStateException("Could not find field \"" + propertyName + "\" for class " + getClass().getName());
            }

            try {
                f.setAccessible(true);
                Object o = f.get(this);
                if(o == null){
                    //Null config class - try to create one...
                    Class<?> c = f.getType();
                    try {
                        o = c.newInstance();
                    } catch (InstantiationException e){
                        throw new RuntimeException("Error creating new instance of configuration object type " + c.getName(), e);
                    }
                    f.set(this, o);
                }
                target.set(o, value);
            } catch (IllegalAccessException e){
                throw new RuntimeException("Error setting configuration field \"" + propertyName + "\" for config field \"" + propertyName
                    + "\" on class " + getClass().getName());
            }

        } else {
            try {
                target.set(this,value);
            } catch (IllegalAccessException e) {
                throw new RuntimeException("Error setting property for function " + getClass().getName(), e);
            }
        }
    }
148393
@SuppressWarnings("unchecked")
    private static void setMapParam(Field field, List<?> values) {
        try {
            // Find Map method: put(Object, Object)
            Class<?> fieldClass = field.getType();
            Method addMethod = fieldClass.getMethod("put", Object.class, Object.class);
            
            // Add each map key/value to field value
            for (Object subParam : values) {
                if (subParam instanceof Map) {
                    Map<String, ?> map = (Map<String, ?>)subParam;
                    for (String key : map.keySet()) {
                        Object value = map.get(key);
                        if (value instanceof List) {
                            // Contains a single element, which is a key/value map
                            value = ((List<?>)value).get(0);
                        }
                        addMethod.invoke(field.get(config), key, value);
                    }
                } else {
                    throw new RuntimeException("Unexpected collection parameter type for '" + field.getName() + ":" + subParam);
                }
            }
        } catch (NoSuchMethodException  | IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
            throw new RuntimeException("Error setting configuration parameter '" + field.getName() + "'", e);
        }
    }
248032
public static void set(Object target, Field field, Object value)
    {
        if (target != null)
        {
            if (!field.isAccessible())
            {
                field.setAccessible(true);
            }
            try
            {
                field.set(target, value);
            }
            catch (IllegalArgumentException iarg)
            {
                throw new PropertyAccessException(iarg);
            }
            catch (IllegalAccessException iacc)
            {
                throw new PropertyAccessException(iacc);
            }
        } // ignore if object is null;
    }
981840
public void setValue(String field, byte[] value) throws IOException {
        int hash = Arrays.hashCode(field.getBytes());
        if (!structure.valueHash2Index.containsKey(hash)) {
            throw new IOException("The field " + field + " is unknown.");
        }
        setValue(structure.valueHash2Index.get(hash), value);
    }
232558
public static void setValue(Object instance, String fieldName, Object value) {
        try {
            Field f = findFieldRecursively(instance.getClass(), fieldName);
            if (f == null)
                throw new NoSuchMethodException("Cannot find field " + fieldName + " on " + instance.getClass() + " or superclasses");
            f.setAccessible(true);
            f.set(instance, value);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
590326
public boolean isSet(_Fields field) {
    if (field == null) {
      throw new IllegalArgumentException();
    }

    switch (field) {
    case OUTPUT_FIELDS:
      return is_set_output_fields();
    case DIRECT:
      return is_set_direct();
    }
    throw new IllegalStateException();
  }
356036
private static void set(Field field, Object obj, String value) throws Exception {
        Class<?> clazz = field.getType();
        field.setAccessible(true);
        if (clazz.equals(Double.class) || clazz.equals(double.class)) {
            double val = Double.valueOf(value);
            field.set(obj, val);
        } else if (clazz.equals(String.class)) {
            field.set(obj, value);
        } else if (clazz.equals(Integer.class) || clazz.equals(int.class)) {
            int val = Integer.parseInt(value);
            field.set(obj, val);
        } else if (clazz.equals(Float.class) || clazz.equals(float.class)) {
            float f = Float.parseFloat(value);
            field.set(obj, f);
        }
    }
694913
public static void setPrivateField(final Object obj, final String name, final Object value) {
        try {
            final Field field = obj.getClass().getDeclaredField(name);
            field.setAccessible(true);
            field.set(obj, value);
        } catch (final Exception ex) {
            throw new RuntimeException("Couldn't set field '" + name + "' in class '" + obj.getClass() + "'", ex);
        }
    }
418042
public static void setFieldValue(final Class<?> source, final Object target, final String fieldName, final Object value) throws NoSuchFieldException
    {
        try
        {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
            {
                @Override
                public Void run() throws Exception
                {
                    Field field = source.getDeclaredField(fieldName);
                    if(!field.isAccessible())
                    {
                        field.setAccessible(true);
                    }
                    field.set(target, value);
                    return null;
                }
            });
        }
        // Unwrap
        catch (final PrivilegedActionException pae)
        {
            final Throwable t = pae.getCause();
            // Rethrow
            if (t instanceof NoSuchFieldException)
            {
                throw (NoSuchFieldException) t;
            }
            else
            {
                // No other checked Exception thrown by Class.getConstructor
                try
                {
                    throw (RuntimeException) t;
                }
                // Just in case we've really messed up
                catch (final ClassCastException cce)
                {
                    throw new RuntimeException("Obtained unchecked Exception; this code should never be reached", t);
                }
            }
        }
    }
421802
void setFieldValue(final Object containingObj, final Object value) {
        try {
            if (value == null) {
                if (primitiveType != PrimitiveType.NON_PRIMITIVE) {
                    throw new IllegalArgumentException("Tried to set primitive-typed field "
                            + field.getDeclaringClass().getName() + "." + field.getName() + " to null value");
                }
                field.set(containingObj, null);
                return;
            }
            switch (primitiveType) {
            case NON_PRIMITIVE:
                field.set(containingObj, value);
                break;
            case INTEGER:
                if (!(value instanceof Integer)) {
                    throw new IllegalArgumentException(
                            "Expected value of type Integer; got " + value.getClass().getName());
                }
                field.setInt(containingObj, (Integer) value);
                break;
            case LONG:
                if (!(value instanceof Long)) {
                    throw new IllegalArgumentException(
                            "Expected value of type Long; got " + value.getClass().getName());
                }
                field.setLong(containingObj, (Long) value);
                break;
            case SHORT:
                if (!(value instanceof Short)) {
                    throw new IllegalArgumentException(
                            "Expected value of type Short; got " + value.getClass().getName());
                }
                field.setShort(containingObj, (Short) value);
                break;
            case DOUBLE:
                if (!(value instanceof Double)) {
                    throw new IllegalArgumentException(
                            "Expected value of type Double; got " + value.getClass().getName());
                }
                field.setDouble(containingObj, (Double) value);
                break;
            case FLOAT:
                if (!(value instanceof Float)) {
                    throw new IllegalArgumentException(
                            "Expected value of type Float; got " + value.getClass().getName());
                }
                field.setFloat(containingObj, (Float) value);
                break;
            case BOOLEAN:
                if (!(value instanceof Boolean)) {
                    throw new IllegalArgumentException(
                            "Expected value of type Boolean; got " + value.getClass().getName());
                }
                field.setBoolean(containingObj, (Boolean) value);
                break;
            case BYTE:
                if (!(value instanceof Byte)) {
                    throw new IllegalArgumentException(
                            "Expected value of type Byte; got " + value.getClass().getName());
                }
                field.setByte(containingObj, (Byte) value);
                break;
            case CHARACTER:
                if (!(value instanceof Character)) {
                    throw new IllegalArgumentException(
                            "Expected value of type Character; got " + value.getClass().getName());
                }
                field.setChar(containingObj, (Character) value);
                break;
            default:
                throw new IllegalArgumentException();
            }
        } catch (IllegalArgumentException | IllegalAccessException e) {
            throw new IllegalArgumentException(
                    "Could not set field " + field.getDeclaringClass().getName() + "." + field.getName(), e);
        }
    }
981675
public Notification setFieldValue(String field, @Nullable String value) {
    fields.put(field, value);
    return this;
  }
303640
@SuppressWarnings("unchecked")
  private void setValue(Object instance, Field field, String value) throws IllegalAccessException {
    if (!field.isAccessible()) {
      field.setAccessible(true);
    }

    Class<?> fieldType = field.getType();

    // Currently only String, primitive (or boxed type) and Enum type are supported.
    if (String.class.equals(fieldType)) {
      field.set(instance, value);
      return;
    }
    if (fieldType.isEnum()) {
      field.set(instance, Enum.valueOf((Class<? extends Enum>) fieldType, value));
      return;
    }

    if (fieldType.isPrimitive()) {
      fieldType = com.google.common.primitives.Primitives.wrap(fieldType);
    }

    try {
      // All box type has the valueOf(String) method.
      field.set(instance, fieldType.getMethod("valueOf", String.class).invoke(null, value));
    } catch (NoSuchMethodException e) {
      // Should never happen, as boxed type always have the valueOf(String) method.
      throw Throwables.propagate(e);
    } catch (InvocationTargetException e) {
      // Also should never happen, as calling method on Java bootstrap classes should always succeed.
      throw Throwables.propagate(e);
    }
  }