Package com.badlogic.gdx.utils.reflect

Examples of com.badlogic.gdx.utils.reflect.Field


      nextClass = nextClass.getSuperclass();
    }

    ObjectMap<String, FieldMetadata> nameToField = new ObjectMap();
    for (int i = 0, n = allFields.size(); i < n; i++) {
      Field field = allFields.get(i);

      if (field.isTransient()) continue;
      if (field.isStatic()) continue;
      if (field.isSynthetic()) continue;

      if (!field.isAccessible()) {
        try {
          field.setAccessible(true);
        } catch (AccessControlException ex) {
          continue;
        }
      }

      nameToField.put(field.getName(), new FieldMetadata(field));
    }
    typeToFields.put(type, nameToField);
    return nameToField;
  }
View Full Code Here


    ObjectMap<String, FieldMetadata> fields = typeToFields.get(type);
    if (fields == null) fields = cacheFields(type);
    int i = 0;
    for (FieldMetadata metadata : new Values<FieldMetadata>(fields)) {
      Field field = metadata.field;
      try {
        Object value = field.get(object);
        if (defaultValues != null) {
          Object defaultValue = defaultValues[i++];
          if (value == null && defaultValue == null) continue;
          if (value != null && defaultValue != null && value.equals(defaultValue)) continue;
        }

        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() + ")");
        throw ex;
      } catch (Exception runtimeEx) {
        SerializationException ex = new SerializationException(runtimeEx);
View Full Code Here

    Object[] values = new Object[fields.size];
    classToDefaultValues.put(type, values);

    int i = 0;
    for (FieldMetadata metadata : fields.values()) {
      Field field = metadata.field;
      try {
        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() + ")");
        throw ex;
      } catch (RuntimeException runtimeEx) {
        SerializationException ex = new SerializationException(runtimeEx);
View Full Code Here

    Class type = object.getClass();
    ObjectMap<String, FieldMetadata> fields = typeToFields.get(type);
    if (fields == null) fields = cacheFields(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);
View Full Code Here

    Class type = object.getClass();
    ObjectMap<String, FieldMetadata> fields = typeToFields.get(type);
    if (fields == null) fields = cacheFields(type);
    FieldMetadata metadata = fields.get(fieldName);
    if (metadata == null) throw new SerializationException("Field not found: " + fieldName + " (" + type.getName() + ")");
    Field field = metadata.field;
    JsonValue jsonValue = jsonMap.get(jsonName);
    if (jsonValue == null) return;
    if (elementType == null) elementType = metadata.elementType;
    try {
      field.set(object, readValue(field.getType(), elementType, jsonValue));
    } 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(field.getName() + " (" + type.getName() + ")");
      throw ex;
    }
  }
View Full Code Here

          if (debug) System.out.println("Ignoring unknown field: " + child.name() + " (" + type.getName() + ")");
          continue;
        } else
          throw new SerializationException("Field not found: " + child.name() + " (" + type.getName() + ")");
      }
      Field field = metadata.field;
      // if (entry.value == null) continue; // I don't remember what this did. :(
      try {
        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(field.getName() + " (" + type.getName() + ")");
        throw ex;
      }
    }
  }
View Full Code Here

      nextClass = nextClass.getSuperclass();
    }

    ObjectMap<String, FieldMetadata> nameToField = new ObjectMap();
    for (int i = 0, n = allFields.size(); i < n; i++) {
      Field field = allFields.get(i);

      if (field.isTransient()) continue;
      if (field.isStatic()) continue;
      if (field.isSynthetic()) continue;

      if (!field.isAccessible()) {
        try {
          field.setAccessible(true);
        } catch (AccessControlException ex) {
          continue;
        }
      }

      nameToField.put(field.getName(), new FieldMetadata(field));
    }
    typeToFields.put(type, nameToField);
    return nameToField;
  }
View Full Code Here

    ObjectMap<String, FieldMetadata> fields = typeToFields.get(type);
    if (fields == null) fields = cacheFields(type);
    int i = 0;
    for (FieldMetadata metadata : new Values<FieldMetadata>(fields)) {
      Field field = metadata.field;
      try {
        Object value = field.get(object);
        if (defaultValues != null) {
          Object defaultValue = defaultValues[i++];
          if (value == null && defaultValue == null) continue;
          if (value != null && defaultValue != null && value.equals(defaultValue)) continue;
        }

        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() + ")");
        throw ex;
      } catch (Exception runtimeEx) {
        SerializationException ex = new SerializationException(runtimeEx);
View Full Code Here

    Object[] values = new Object[fields.size];
    classToDefaultValues.put(type, values);

    int i = 0;
    for (FieldMetadata metadata : fields.values()) {
      Field field = metadata.field;
      try {
        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() + ")");
        throw ex;
      } catch (RuntimeException runtimeEx) {
        SerializationException ex = new SerializationException(runtimeEx);
View Full Code Here

    Class type = object.getClass();
    ObjectMap<String, FieldMetadata> fields = typeToFields.get(type);
    if (fields == null) fields = cacheFields(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);
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.utils.reflect.Field

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.