public static <T extends Element> T changeValue(Element parent, T oldValue, T newValue) { if (oldValue != newValue) { if (oldValue != null) oldValue.setParentElement(null); if (newValue != null) newValue.setParentElement(parent); } return newValue; }
public static <T extends Element> void changeValue(Element parent, List<T> oldValue, List<T> newValue) { for (T t : oldValue) t.setParentElement(null); oldValue.clear(); if (newValue != null) { for (T t : newValue) { if (t == null) continue; t.setParentElement(parent); oldValue.add(t); } } } public static <T extends Element> void changeValue(Element parent, Map<String, T> oldValue, Map<String, T> newValue) {
public static <T extends Element> void changeValue(Element parent, Map<String, T> oldValue, Map<String, T> newValue) { for (T t : oldValue.values()) t.setParentElement(null); oldValue.clear(); if (newValue != null) { for (String name : newValue.keySet()) { T t = newValue.get(name); if (t == null) continue; t.setParentElement(parent); oldValue.put(name, t); } } } public static <T extends Element> T changeValue(Element parent, T oldValue, T newValue) {
@SuppressWarnings("unchecked") public static <T extends Element> boolean replaceChild(Map<String, T> map, Class<T> type, Element parent, Element child, Element by) { String i = indexOfInstance(child, map); if (i != null) { T old; if (by == null) old = map.remove(i); else old = map.put(i, type == null ? (T)by : type.cast(by)); if (old != by) { if (old != null) old.setParentElement(null); if (by != null) by.setParentElement(parent); } return true; } return false; }
@SuppressWarnings("unchecked") public static <T extends Element> boolean replaceChild(List<T> list, Class<T> type, Element parent, Element child, Element by) { int i = indexOfInstance(child, list); if (i >= 0) { T old; if (by == null) old = list.remove(i); else old = list.set(i, type == null ? (T)by : type.cast(by)); if (old != by) { if (old != null) old.setParentElement(null); if (by != null) by.setParentElement(parent); } return true; } return false; }
public final MutableByDeclarator mutateTypeKeepingParent(MutableByDeclarator type) { if (type == null) return null; MutableByDeclarator mutated = mutateType(type); if (mutated == null) throw new RuntimeException("Mutation of " + type + " yielded NULL!"); ((Element)mutated).setParentElement(((Element)type).getParentElement()); return mutated; } public static class DirectDeclarator extends Declarator {
childToInsert.setParentElement(this); return true; } catch (Exception e) {