public static <T extends DomElement> T addElementAfter(@NotNull final T anchor) { final DomElement parent = anchor.getParent(); final DomCollectionChildDescription childDescription = (DomCollectionChildDescription) anchor.getChildDescription(); assert parent != null; final List<? extends DomElement> list = childDescription.getValues(parent); final int i = list.indexOf(anchor); assert i >= 0; return (T) childDescription.addValue(parent, i + 1); }
@SuppressWarnings("ForLoopReplaceableByForEach") public static <T extends DomElement> List<T> getChildrenOf( DomElement parent, final Class<T> type) { final List<T> list = new SmartList<>(); List<? extends AbstractDomChildrenDescription> descriptions = parent.getGenericInfo().getChildrenDescriptions(); for (int i = 0, descriptionsSize = descriptions.size(); i < descriptionsSize; i++) { AbstractDomChildrenDescription description = descriptions.get(i); if (description.getType() instanceof Class && type.isAssignableFrom((Class<?>) description.getType())) { List<T> values = (List<T>) description.getValues(parent); for (int j = 0, valuesSize = values.size(); j < valuesSize; j++) { T value = values.get(j); if (value.exists()) { list.add(value); } } } } return list; }