@NotNull private XmlAttribute[] calculateAttributes(final Map<String, String> attributesValueMap) { final List<XmlAttribute> result = new ArrayList<XmlAttribute>(10); processChildren( new PsiElementProcessor() { public boolean execute(@NotNull PsiElement element) { if (element instanceof XmlAttribute) { XmlAttribute attribute = (XmlAttribute) element; result.add(attribute); cacheOneAttributeValue(attribute.getName(), attribute.getValue(), attributesValueMap); myHaveNamespaceDeclarations = myHaveNamespaceDeclarations || attribute.isNamespaceDeclaration(); } else if (element instanceof XmlToken && ((XmlToken) element).getTokenType() == XmlTokenType.XML_TAG_END) { return false; } return true; } }); if (result.isEmpty()) { return XmlAttribute.EMPTY_ARRAY; } else { return ContainerUtil.toArray(result, new XmlAttribute[result.size()]); } }
@NotNull public PsiReference[] getReferences() { ProgressManager.checkCanceled(); final ASTNode startTagName = XmlChildRole.START_TAG_NAME_FINDER.findChild(this); if (startTagName == null) return PsiReference.EMPTY_ARRAY; final ASTNode endTagName = XmlChildRole.CLOSING_TAG_NAME_FINDER.findChild(this); List<PsiReference> refs = new ArrayList<PsiReference>(); String prefix = getNamespacePrefix(); TagNameReference startTagRef = TagNameReference.createTagNameReference(this, startTagName, true); refs.add(startTagRef); if (prefix.length() > 0) { refs.add(createPrefixReference(startTagName, prefix, startTagRef)); } if (endTagName != null) { TagNameReference endTagRef = TagNameReference.createTagNameReference(this, endTagName, false); refs.add(endTagRef); prefix = XmlUtil.findPrefixByQualifiedName(endTagName.getText()); if (StringUtil.isNotEmpty(prefix)) { refs.add(createPrefixReference(endTagName, prefix, endTagRef)); } } // ArrayList.addAll() makes a clone of the collection //noinspection ManualArrayToCollectionCopy for (PsiReference ref : ReferenceProvidersRegistry.getReferencesFromProviders(this, XmlTag.class)) { refs.add(ref); } return ContainerUtil.toArray(refs, new PsiReference[refs.size()]); }
@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; }
private PsiElement[] getElements() { final List<PsiElement> elements = new ArrayList<PsiElement>(); processElements( new PsiElementProcessor() { public boolean execute(@NotNull PsiElement psiElement) { elements.add(psiElement); return true; } }, this); return ContainerUtil.toArray(elements, new PsiElement[elements.size()]); }
@NotNull public XmlTag[] findSubTags(final String name, final String namespace) { final XmlTag[] subTags = getSubTags(); final List<XmlTag> result = new ArrayList<XmlTag>(); for (final XmlTag subTag : subTags) { if (namespace == null) { if (name.equals(subTag.getName())) result.add(subTag); } else if (name.equals(subTag.getLocalName()) && namespace.equals(subTag.getNamespace())) { result.add(subTag); } } return ContainerUtil.toArray(result, new XmlTag[result.size()]); }
@NotNull public XmlTagValue getValue() { XmlTagValue tagValue = myValue; if (tagValue == null) { final PsiElement[] elements = getElements(); final List<XmlTagChild> bodyElements = new ArrayList<XmlTagChild>(elements.length); boolean insideBody = false; for (final PsiElement element : elements) { final ASTNode treeElement = element.getNode(); if (insideBody) { if (treeElement.getElementType() == XmlTokenType.XML_END_TAG_START) break; if (!(element instanceof XmlTagChild)) continue; bodyElements.add((XmlTagChild) element); } else if (treeElement.getElementType() == XmlTokenType.XML_TAG_END) insideBody = true; } XmlTagChild[] tagChildren = ContainerUtil.toArray(bodyElements, new XmlTagChild[bodyElements.size()]); myValue = tagValue = new XmlTagValueImpl(tagChildren, this); } return tagValue; }