private <T> T find (Array<?> array, Class<T> type) { for (Object object : array) { if (ClassReflection.isAssignableFrom(type, object.getClass())) return (T)object; } return null; }
private <T> T find (Array<?> array, Class<T> type) { for (Object object : array) { if (ClassReflection.isAssignableFrom(type, object.getClass())) return (T)object; } return null; }
/** @return the index of the Influencer of the given type. */ private <K extends Influencer> int findIndex (Class<K> type) { for (int i = 0; i < influencers.size; ++i) { Influencer influencer = influencers.get(i); if (ClassReflection.isAssignableFrom(type, influencer.getClass())) { return i; } } return -1; }
/** @return the index of the Influencer of the given type. */ private <K extends Influencer> int findIndex (Class<K> type) { for (int i = 0; i < influencers.size; ++i) { Influencer influencer = influencers.get(i); if (ClassReflection.isAssignableFrom(type, influencer.getClass())) { return i; } } return -1; }
public FieldMetadata (Field field) { this.field = field; int index = (ClassReflection.isAssignableFrom(ObjectMap.class, field.getType()) || ClassReflection.isAssignableFrom(Map.class, field.getType())) ? 1 : 0; this.elementType = field.getElementType(index); } }
public FieldMetadata (Field field) { this.field = field; int index = (ClassReflection.isAssignableFrom(ObjectMap.class, field.getType()) || ClassReflection.isAssignableFrom(Map.class, field.getType())) ? 1 : 0; this.elementType = field.getElementType(index); } }
private Object copy(Object object) { try { Constructor theConstructor = null; for (Constructor constructor : ClassReflection.getConstructors(object.getClass())) { if (constructor.getParameterTypes().length == 1 && ClassReflection.isAssignableFrom(constructor.getParameterTypes()[0], object.getClass())) { theConstructor = constructor; break; } } return theConstructor.newInstance(object); } catch (Throwable ex) { throw new GdxRuntimeException(ex); } }
public <T> T readValue (Class<T> type, Class elementType, JsonValue jsonData) { // If the JSON is a string but the type is not, look up the actual value by name. if (jsonData.isString() && !ClassReflection.isAssignableFrom(CharSequence.class, type)) return get(jsonData.asString(), type); return super.readValue(type, elementType, jsonData); }
public <T> T readValue (Class<T> type, Class elementType, JsonValue jsonData) { // If the JSON is a string but the type is not, look up the actual value by name. if (jsonData.isString() && !ClassReflection.isAssignableFrom(CharSequence.class, type)) return get(jsonData.asString(), type); return super.readValue(type, elementType, jsonData); }
protected Object newInstance (Class type) { try { return ClassReflection.newInstance(type); } catch (Exception ex) { try { // Try a private constructor. Constructor constructor = ClassReflection.getDeclaredConstructor(type); constructor.setAccessible(true); return constructor.newInstance(); } catch (SecurityException ignored) { } catch (ReflectionException ignored) { if (ClassReflection.isAssignableFrom(Enum.class, type)) { if (type.getEnumConstants() == null) type = type.getSuperclass(); return type.getEnumConstants()[0]; } if (type.isArray()) throw new SerializationException("Encountered JSON object when expected array of type: " + type.getName(), ex); else if (ClassReflection.isMemberClass(type) && !ClassReflection.isStaticClass(type)) throw new SerializationException("Class cannot be created (non-static member class): " + type.getName(), ex); else throw new SerializationException("Class cannot be created (missing no-arg constructor): " + type.getName(), ex); } catch (Exception privateConstructorException) { ex = privateConstructorException; } throw new SerializationException("Error constructing instance of class: " + type.getName(), ex); } }
protected Object newInstance (Class type) { try { return ClassReflection.newInstance(type); } catch (Exception ex) { try { // Try a private constructor. Constructor constructor = ClassReflection.getDeclaredConstructor(type); constructor.setAccessible(true); return constructor.newInstance(); } catch (SecurityException ignored) { } catch (ReflectionException ignored) { if (ClassReflection.isAssignableFrom(Enum.class, type)) { if (type.getEnumConstants() == null) type = type.getSuperclass(); return type.getEnumConstants()[0]; } if (type.isArray()) throw new SerializationException("Encountered JSON object when expected array of type: " + type.getName(), ex); else if (ClassReflection.isMemberClass(type) && !ClassReflection.isStaticClass(type)) throw new SerializationException("Class cannot be created (non-static member class): " + type.getName(), ex); else throw new SerializationException("Class cannot be created (missing no-arg constructor): " + type.getName(), ex); } catch (Exception privateConstructorException) { ex = privateConstructorException; } throw new SerializationException("Error constructing instance of class: " + type.getName(), ex); } }
private void readNamedObjects (Json json, Class type, JsonValue valueMap) { Class addType = type == TintedDrawable.class ? Drawable.class : type; for (JsonValue valueEntry = valueMap.child; valueEntry != null; valueEntry = valueEntry.next) { Object object = json.readValue(type, valueEntry); if (object == null) continue; try { add(valueEntry.name, object, addType); if (addType != Drawable.class && ClassReflection.isAssignableFrom(Drawable.class, addType)) add(valueEntry.name, object, Drawable.class); } catch (Exception ex) { throw new SerializationException( "Error reading " + ClassReflection.getSimpleName(type) + ": " + valueEntry.name, ex); } } } });
private void readNamedObjects (Json json, Class type, JsonValue valueMap) { Class addType = type == TintedDrawable.class ? Drawable.class : type; for (JsonValue valueEntry = valueMap.child; valueEntry != null; valueEntry = valueEntry.next) { Object object = json.readValue(type, valueEntry); if (object == null) continue; try { add(valueEntry.name, object, addType); if (addType != Drawable.class && ClassReflection.isAssignableFrom(Drawable.class, addType)) add(valueEntry.name, object, Drawable.class); } catch (Exception ex) { throw new SerializationException( "Error reading " + ClassReflection.getSimpleName(type) + ": " + valueEntry.name, ex); } } } });
if (typeName != null && ClassReflection.isAssignableFrom(Collection.class, type)) { || type == Character.class || ClassReflection.isAssignableFrom(Enum.class, type)) { return readValue("value", type, jsonData); if (serializer != null) return (T)serializer.read(this, jsonData, type); if (ClassReflection.isAssignableFrom(Serializable.class, type)) { if (ClassReflection.isAssignableFrom(Array.class, type)) { Array result = type == Array.class ? new Array() : (Array)newInstance(type); for (JsonValue child = jsonData.child; child != null; child = child.next) return (T)result; if (ClassReflection.isAssignableFrom(Queue.class, type)) { Queue result = type == Queue.class ? new Queue() : (Queue)newInstance(type); for (JsonValue child = jsonData.child; child != null; child = child.next) return (T)result; if (ClassReflection.isAssignableFrom(Collection.class, type)) { Collection result = type.isInterface() ? new ArrayList() : (Collection)newInstance(type); for (JsonValue child = jsonData.child; child != null; child = child.next) if (ClassReflection.isAssignableFrom(Enum.class, type)) { Enum[] constants = (Enum[])type.getEnumConstants(); for (int i = 0, n = constants.length; i < n; i++) {
if (typeName != null && ClassReflection.isAssignableFrom(Collection.class, type)) { || type == Character.class || ClassReflection.isAssignableFrom(Enum.class, type)) { return readValue("value", type, jsonData); if (serializer != null) return (T)serializer.read(this, jsonData, type); if (ClassReflection.isAssignableFrom(Serializable.class, type)) { if (ClassReflection.isAssignableFrom(Array.class, type)) { Array result = type == Array.class ? new Array() : (Array)newInstance(type); for (JsonValue child = jsonData.child; child != null; child = child.next) return (T)result; if (ClassReflection.isAssignableFrom(Queue.class, type)) { Queue result = type == Queue.class ? new Queue() : (Queue)newInstance(type); for (JsonValue child = jsonData.child; child != null; child = child.next) return (T)result; if (ClassReflection.isAssignableFrom(Collection.class, type)) { Collection result = type.isInterface() ? new ArrayList() : (Collection)newInstance(type); for (JsonValue child = jsonData.child; child != null; child = child.next) if (ClassReflection.isAssignableFrom(Enum.class, type)) { Enum[] constants = (Enum[])type.getEnumConstants(); for (int i = 0, n = constants.length; i < n; i++) {
if (ClassReflection.isAssignableFrom(Enum.class, actualType)) { if (typeName != null && (knownType == null || knownType != actualType)) {
if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass())) interpolationMembers++; if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass())) interpolationNames[i] = interpolationFields[i].getName(); selectedInterpolation = interpolationNames[0];
if (ClassReflection.isAssignableFrom(Enum.class, actualType)) { if (typeName != null && (knownType == null || knownType != actualType)) {
else if (type == byte.class || type == Byte.class) ret = numberValue.byteValue(); else if (ClassReflection.isAssignableFrom(Distribution.class, type)) { @SuppressWarnings("unchecked") Class<Distribution> distributionType = (Class<Distribution>)type; if (stringValue.length() != 1) throw new GdxRuntimeException("Invalid character '" + value + "'"); ret = Character.valueOf(stringValue.charAt(0)); } else if (ClassReflection.isAssignableFrom(Distribution.class, type)) { @SuppressWarnings("unchecked") Class<Distribution> distributionType = (Class<Distribution>)type; ret = btParser.distributionAdapters.toDistribution(stringValue, distributionType); } else if (ClassReflection.isAssignableFrom(Enum.class, type)) { Enum<?>[] constants = (Enum<?>[])type.getEnumConstants(); for (int i = 0, n = constants.length; i < n; i++) {
public FieldMetadata (Field field) { this.field = field; int index = (ClassReflection.isAssignableFrom(ObjectMap.class, field.getType()) || ClassReflection.isAssignableFrom(Map.class, field.getType())) ? 1 : 0; this.elementType = field.getElementType(index); } }