/** Sets the value of the field on the supplied object. */ public void set (Object obj, Object value) throws ReflectionException { try { field.set(obj, value); } catch (IllegalArgumentException e) { throw new ReflectionException("Argument not valid for field: " + getName(), e); } catch (IllegalAccessException e) { throw new ReflectionException("Illegal access to field: " + getName(), e); } }
/** Sets the value of the field on the supplied object. */ public void set (Object obj, Object value) throws ReflectionException { try { field.set(obj, value); } catch (IllegalArgumentException e) { throw new ReflectionException("Argument not valid for field: " + getName(), e); } catch (IllegalAccessException e) { throw new ReflectionException("Illegal access to field: " + getName(), e); } }
/** Returns the value of the field on the supplied object. */ public Object get (Object obj) throws ReflectionException { try { return field.get(obj); } catch (IllegalArgumentException e) { throw new ReflectionException("Object is not an instance of " + getDeclaringClass(), e); } catch (IllegalAccessException e) { throw new ReflectionException("Illegal access to field: " + getName(), e); } }
/** Returns the value of the field on the supplied object. */ public Object get (Object obj) throws ReflectionException { try { return field.get(obj); } catch (IllegalArgumentException e) { throw new ReflectionException("Object is not an instance of " + getDeclaringClass(), e); } catch (IllegalAccessException e) { throw new ReflectionException("Illegal access to field: " + getName(), e); } }
if (debug) System.out.println("Writing field: " + field.getName() + " (" + type.getName() + ")"); writer.name(field.getName()); writeValue(value, field.getType(), metadata.elementType); } catch (ReflectionException ex) { throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex); } catch (SerializationException ex) { ex.addTrace(field + " (" + type.getName() + ")");
if (debug) System.out.println("Writing field: " + field.getName() + " (" + type.getName() + ")"); writer.name(field.getName()); writeValue(value, field.getType(), metadata.elementType); } catch (ReflectionException ex) { throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex); } catch (SerializationException ex) { ex.addTrace(field + " (" + type.getName() + ")");
/** @param object May be null if the field is static. * @param elementType May be null if the type is unknown. */ public void readField (Object object, Field field, String jsonName, Class elementType, JsonValue jsonMap) { JsonValue jsonValue = jsonMap.get(jsonName); if (jsonValue == null) return; try { field.set(object, readValue(field.getType(), elementType, jsonValue)); } catch (ReflectionException ex) { throw new SerializationException( "Error accessing field: " + field.getName() + " (" + field.getDeclaringClass().getName() + ")", ex); } catch (SerializationException ex) { ex.addTrace(field.getName() + " (" + field.getDeclaringClass().getName() + ")"); throw ex; } catch (RuntimeException runtimeEx) { SerializationException ex = new SerializationException(runtimeEx); ex.addTrace(jsonValue.trace()); ex.addTrace(field.getName() + " (" + field.getDeclaringClass().getName() + ")"); throw ex; } }
/** @param object May be null if the field is static. * @param elementType May be null if the type is unknown. */ public void readField (Object object, Field field, String jsonName, Class elementType, JsonValue jsonMap) { JsonValue jsonValue = jsonMap.get(jsonName); if (jsonValue == null) return; try { field.set(object, readValue(field.getType(), elementType, jsonValue)); } catch (ReflectionException ex) { throw new SerializationException( "Error accessing field: " + field.getName() + " (" + field.getDeclaringClass().getName() + ")", ex); } catch (SerializationException ex) { ex.addTrace(field.getName() + " (" + field.getDeclaringClass().getName() + ")"); throw ex; } catch (RuntimeException runtimeEx) { SerializationException ex = new SerializationException(runtimeEx); ex.addTrace(jsonValue.trace()); ex.addTrace(field.getName() + " (" + field.getDeclaringClass().getName() + ")"); throw ex; } }
/** Writes the specified field to the current JSON object. * @param elementType May be null if the type is unknown. */ public void writeField (Object object, String fieldName, String jsonName, Class elementType) { Class type = object.getClass(); ObjectMap<String, FieldMetadata> fields = getFields(type); FieldMetadata metadata = fields.get(fieldName); if (metadata == null) throw new SerializationException("Field not found: " + fieldName + " (" + type.getName() + ")"); Field field = metadata.field; if (elementType == null) elementType = metadata.elementType; try { if (debug) System.out.println("Writing field: " + field.getName() + " (" + type.getName() + ")"); writer.name(jsonName); writeValue(field.get(object), field.getType(), elementType); } catch (ReflectionException ex) { throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex); } catch (SerializationException ex) { ex.addTrace(field + " (" + type.getName() + ")"); throw ex; } catch (Exception runtimeEx) { SerializationException ex = new SerializationException(runtimeEx); ex.addTrace(field + " (" + type.getName() + ")"); throw ex; } }
field.set(object, readValue(field.getType(), metadata.elementType, child)); } catch (ReflectionException ex) { throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex); } catch (SerializationException ex) { ex.addTrace(field.getName() + " (" + type.getName() + ")"); throw ex; } catch (RuntimeException runtimeEx) { SerializationException ex = new SerializationException(runtimeEx); ex.addTrace(child.trace()); ex.addTrace(field.getName() + " (" + type.getName() + ")"); throw ex;
/** Writes the specified field to the current JSON object. * @param elementType May be null if the type is unknown. */ public void writeField (Object object, String fieldName, String jsonName, Class elementType) { Class type = object.getClass(); ObjectMap<String, FieldMetadata> fields = getFields(type); FieldMetadata metadata = fields.get(fieldName); if (metadata == null) throw new SerializationException("Field not found: " + fieldName + " (" + type.getName() + ")"); Field field = metadata.field; if (elementType == null) elementType = metadata.elementType; try { if (debug) System.out.println("Writing field: " + field.getName() + " (" + type.getName() + ")"); writer.name(jsonName); writeValue(field.get(object), field.getType(), elementType); } catch (ReflectionException ex) { throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex); } catch (SerializationException ex) { ex.addTrace(field + " (" + type.getName() + ")"); throw ex; } catch (Exception runtimeEx) { SerializationException ex = new SerializationException(runtimeEx); ex.addTrace(field + " (" + type.getName() + ")"); throw ex; } }
/** Each field on the <code>to</code> object is set to the value for the field with the same name on the <code>from</code> * object. The <code>to</code> object must have at least all the fields of the <code>from</code> object with the same name and * type. */ public void copyFields (Object from, Object to) { ObjectMap<String, FieldMetadata> toFields = getFields(from.getClass()); for (ObjectMap.Entry<String, FieldMetadata> entry: getFields(from.getClass())) { FieldMetadata toField = toFields.get(entry.key); Field fromField = entry.value.field; if (toField == null) throw new SerializationException("To object is missing field" + entry.key); try { toField.field.set(to, fromField.get(from)); } catch (ReflectionException ex) { throw new SerializationException("Error copying field: " + fromField.getName(), ex); } } }
field.set(object, readValue(field.getType(), metadata.elementType, child)); } catch (ReflectionException ex) { throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex); } catch (SerializationException ex) { ex.addTrace(field.getName() + " (" + type.getName() + ")"); throw ex; } catch (RuntimeException runtimeEx) { SerializationException ex = new SerializationException(runtimeEx); ex.addTrace(child.trace()); ex.addTrace(field.getName() + " (" + type.getName() + ")"); throw ex;
/** Each field on the <code>to</code> object is set to the value for the field with the same name on the <code>from</code> * object. The <code>to</code> object must have at least all the fields of the <code>from</code> object with the same name and * type. */ public void copyFields (Object from, Object to) { ObjectMap<String, FieldMetadata> toFields = getFields(from.getClass()); for (ObjectMap.Entry<String, FieldMetadata> entry: getFields(from.getClass())) { FieldMetadata toField = toFields.get(entry.key); Field fromField = entry.value.field; if (toField == null) throw new SerializationException("To object is missing field" + entry.key); try { toField.field.set(to, fromField.get(from)); } catch (ReflectionException ex) { throw new SerializationException("Error copying field: " + fromField.getName(), ex); } } }
nameToField.put(field.getName(), new FieldMetadata(field));
nameToField.put(field.getName(), new FieldMetadata(field));
values[i++] = field.get(object); } catch (ReflectionException ex) { throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex); } catch (SerializationException ex) { ex.addTrace(field + " (" + type.getName() + ")");
values[i++] = field.get(object); } catch (ReflectionException ex) { throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex); } catch (SerializationException ex) { ex.addTrace(field + " (" + type.getName() + ")");
for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass())) interpolationNames[i] = interpolationFields[i].getName(); selectedInterpolation = interpolationNames[0];
private void setField (Field field, Task<E> task, Object value) { field.setAccessible(true); Object valueObject = castValue(field, value); if (valueObject == null) throwAttributeTypeException(getCurrentTask().name, field.getName(), field.getType().getSimpleName()); try { field.set(task, valueObject); } catch (ReflectionException e) { throw new GdxRuntimeException(e); } }