@NotNull public static String[] getElementNames(@NotNull Collection<? extends DomElement> list) { ArrayList<String> result = new ArrayList<>(list.size()); if (list.size() > 0) { for (DomElement element : list) { String name = element.getGenericInfo().getElementName(element); if (name != null) { result.add(name); } } } return ArrayUtil.toStringArray(result); }
public static List<? extends DomElement> getIdentitySiblings(DomElement element) { final GenericDomValue nameDomElement = element.getGenericInfo().getNameDomElement(element); if (nameDomElement == null) return Collections.emptyList(); final NameValue nameValue = nameDomElement.getAnnotation(NameValue.class); if (nameValue == null || !nameValue.unique()) return Collections.emptyList(); final String stringValue = ElementPresentationManager.getElementName(element); if (stringValue == null) return Collections.emptyList(); final DomElement scope = element.getManager().getIdentityScope(element); if (scope == null) return Collections.emptyList(); final DomGenericInfo domGenericInfo = scope.getGenericInfo(); final String tagName = element.getXmlElementName(); final DomCollectionChildDescription childDescription = domGenericInfo.getCollectionChildDescription(tagName, element.getXmlElementNamespaceKey()); if (childDescription != null) { final ArrayList<DomElement> list = new ArrayList<>(childDescription.getValues(scope)); list.remove(element); return list; } return Collections.emptyList(); }
@Nullable private static JavaMethod getGetterMethod(final DomElement element, final DomElement parent) { final String xmlElementName = element.getXmlElementName(); final String namespace = element.getXmlElementNamespaceKey(); final DomGenericInfo genericInfo = parent.getGenericInfo(); if (element instanceof GenericAttributeValue) { final DomAttributeChildDescription description = genericInfo.getAttributeChildDescription(xmlElementName, namespace); assert description != null; return description.getGetterMethod(); } final DomFixedChildDescription description = genericInfo.getFixedChildDescription(xmlElementName, namespace); return description != null ? description.getGetterMethod(description.getValues(parent).indexOf(element)) : null; }
@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; }