public void registerConstant(final Class<?> c, final String privateFieldName) { try { List<Field> fields = allFields(c); for (Field field : fields) { if (field.getName().equals(privateFieldName)) { field.setAccessible(true); final Object v = field.get(null); ignoredInstances.put(v, true); return; } } throw new RuntimeException("No such field : " + privateFieldName); } catch (final SecurityException e) { throw new RuntimeException(e); } catch (final IllegalArgumentException e) { throw new RuntimeException(e); } catch (final IllegalAccessException e) { throw new RuntimeException(e); } }
public void registerConstant(final Class<?> c, final String privateFieldName) { try { List<Field> fields = allFields(c); for (Field field : fields) { if (field.getName().equals(privateFieldName)) { field.setAccessible(true); final Object v = field.get(null); ignoredInstances.put(v, true); return; } } throw new RuntimeException("No such field : " + privateFieldName); } catch (final SecurityException e) { throw new RuntimeException(e); } catch (final IllegalArgumentException e) { throw new RuntimeException(e); } catch (final IllegalAccessException e) { throw new RuntimeException(e); } }
/** * registers all static fields of these classes. Those static fields won't be cloned when an instance * of the class is cloned. * * This is useful i.e. when a static field object is added into maps or sets. At that point, there is no * way for the cloner to know that it was static except if it is registered. * * @param classes array of classes */ public void registerStaticFields(final Class<?>... classes) { for (final Class<?> c : classes) { final List<Field> fields = allFields(c); for (final Field field : fields) { final int mods = field.getModifiers(); if (Modifier.isStatic(mods) && !field.getType().isPrimitive()) { registerConstant(c, field.getName()); } } } }
/** * registers all static fields of these classes. Those static fields won't be cloned when an instance * of the class is cloned. * * This is useful i.e. when a static field object is added into maps or sets. At that point, there is no * way for the cloner to know that it was static except if it is registered. * * @param classes array of classes */ public void registerStaticFields(final Class<?>... classes) { for (final Class<?> c : classes) { final List<Field> fields = allFields(c); for (final Field field : fields) { final int mods = field.getModifiers(); if (Modifier.isStatic(mods) && !field.getType().isPrimitive()) { registerConstant(c, field.getName()); } } } }
private <T> T cloneObject(T o, Map<Object, Object> clones, Class<T> clz) throws IllegalAccessException { final T newInstance = newInstance(clz); if (clones != null) { clones.put(o, newInstance); } final List<Field> fields = allFields(clz); for (final Field field : fields) { final int modifiers = field.getModifiers(); if (!Modifier.isStatic(modifiers)) { if (!(nullTransient && Modifier.isTransient(modifiers))) { // request by Jonathan : transient fields can be null-ed final Object fieldObject = field.get(o); final boolean shouldClone = (cloneSynthetics || !field.isSynthetic()) && (cloneAnonymousParent || !isAnonymousParent(field)); final Object fieldObjectClone = clones != null ? (shouldClone ? applyCloningStrategy(clones, o, fieldObject, field) : fieldObject) : fieldObject; field.set(newInstance, fieldObjectClone); if (dumpCloned != null && fieldObjectClone != fieldObject) { dumpCloned.cloning(field, o.getClass()); } } } } return newInstance; }
private <T> T cloneObject(T o, Map<Object, Object> clones, Class<T> clz) throws IllegalAccessException { final T newInstance = newInstance(clz); if (clones != null) { clones.put(o, newInstance); } final List<Field> fields = allFields(clz); for (final Field field : fields) { final int modifiers = field.getModifiers(); if (!Modifier.isStatic(modifiers)) { if (!(nullTransient && Modifier.isTransient(modifiers))) { // request by Jonathan : transient fields can be null-ed final Object fieldObject = field.get(o); final boolean shouldClone = (cloneSynthetics || !field.isSynthetic()) && (cloneAnonymousParent || !isAnonymousParent(field)); final Object fieldObjectClone = clones != null ? (shouldClone ? applyCloningStrategy(clones, o, fieldObject, field) : fieldObject) : fieldObject; field.set(newInstance, fieldObjectClone); if (dumpCloned != null && fieldObjectClone != fieldObject) { dumpCloned.cloning(field, o.getClass()); } } } } return newInstance; }