/** @return the {@link #selectedInterpolation selected} interpolation */ private Interpolation getInterpolation (String name) { try { return (Interpolation)ClassReflection.getField(Interpolation.class, name).get(null); } catch (Exception e) { throw new RuntimeException(e); } }
/** 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); } } }
if (readDeprecated && ignoreDeprecated && field.isAnnotationPresent(Deprecated.class)) continue; try { Object value = field.get(object); if (defaultValues != null) { Object defaultValue = defaultValues[i++];
/** 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); } } }
if (readDeprecated && ignoreDeprecated && field.isAnnotationPresent(Deprecated.class)) continue; try { Object value = field.get(object); if (defaultValues != null) { Object defaultValue = defaultValues[i++];
if (readDeprecated && ignoreDeprecated && field.isAnnotationPresent(Deprecated.class)) continue; try { values[i++] = field.get(object); } catch (ReflectionException ex) { throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex);
private void installGdxReflections() { try { gdxClazz = ClassReflection.forName("com.badlogic.gdx.Gdx"); gdxAppObject = ClassReflection.getField(gdxClazz, "app").get(null); } catch (ReflectionException e) { e.printStackTrace(); throw new RuntimeException("No libGDX environment. \n"); } }
/** 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; } }
if (readDeprecated && ignoreDeprecated && field.isAnnotationPresent(Deprecated.class)) continue; try { values[i++] = field.get(object); } catch (ReflectionException ex) { throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex);
private void installGdxReflections() { try { gdxClazz = ClassReflection.forName("com.badlogic.gdx.Gdx"); gdxAppObject = ClassReflection.getField(gdxClazz, "app").get(null); } catch (ReflectionException e) { e.printStackTrace(); throw new RuntimeException("No libGDX environment. \n"); } }
if (readDeprecated && ignoreDeprecated && field.isAnnotationPresent(Deprecated.class)) continue; try { Object value = field.get(object); if (defaultValues != null) { Object defaultValue = defaultValues[i++];
/** 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); } } }
public DeserializedCollection(Field field, Class<?> fieldClass, Object object) throws ReflectionException { super(); this.field = field; this.fieldClass = fieldClass; if(field.isFinal()) { collection = (T) field.get(object); } else { collection = (T) (fieldClass.isInterface() ? ClassReflection.newInstance(getFallbackImplementation()) : ClassReflection.newInstance(fieldClass)); field.set(object, collection); } }
/** 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; } }
if (readDeprecated && ignoreDeprecated && field.isAnnotationPresent(Deprecated.class)) continue; try { values[i++] = field.get(object); } catch (ReflectionException ex) { throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex);
public DeserializedMap(Field field, Class<?> fieldClass, Object object) throws ReflectionException { super(); this.field = field; this.fieldClass = fieldClass; if(field.isFinal()) { map = (T) field.get(object); } else { map = (T) (fieldClass.isInterface() ? ClassReflection.newInstance(getFallbackImplementation()) : ClassReflection.newInstance(fieldClass)); field.set(object, map); } }
boolean fieldValueBoolean = false; try { fieldValueBoolean = (Boolean)field.get(field); } catch (Exception e) { Gdx.app.debug(TAG, "Cannot parse value for boolean " + field.getName());
float fieldValueFloat = 0; try { fieldValueFloat = (Float)field.get(field); } catch (Exception e) { Gdx.app.debug(TAG, "Cannot parse float value for " + field.getName());