Exemplo n.º 1
0
 @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;
 }
Exemplo n.º 2
0
 public String getPrefixByNamespace(String namespace) {
   final PsiElement parent = getParent();
   BidirectionalMap<String, String> map = initNamespaceMaps(parent);
   if (map != null) {
     List<String> keysByValue = map.getKeysByValue(namespace);
     final String ns = keysByValue == null || keysByValue.isEmpty() ? null : keysByValue.get(0);
     if (ns != null) return ns;
   }
   if (parent instanceof XmlTag) return ((XmlTag) parent).getPrefixByNamespace(namespace);
   // The prefix 'xml' is by definition bound to the namespace name
   // http://www.w3.org/XML/1998/namespace. It MAY, but need not, be declared
   if (XmlUtil.XML_NAMESPACE_URI.equals(namespace)) return XML_NS_PREFIX;
   return null;
 }