use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class TagNameVariantCollector method getTagDescriptors.
public static List<XmlElementDescriptor> getTagDescriptors(final XmlTag element, final Collection<String> namespaces, @Nullable List<String> nsInfo) {
XmlElementDescriptor elementDescriptor = null;
String elementNamespace = element.getNamespacePrefix().isEmpty() ? null : element.getNamespace();
final Map<String, XmlElementDescriptor> descriptorsMap = new HashMap<>();
PsiElement context = element.getParent();
PsiElement curElement = element.getParent();
while (curElement instanceof XmlTag) {
final XmlTag declarationTag = (XmlTag) curElement;
final String namespace = declarationTag.getNamespace();
if (!descriptorsMap.containsKey(namespace)) {
final XmlElementDescriptor descriptor = declarationTag.getDescriptor();
if (descriptor != null) {
descriptorsMap.put(namespace, descriptor);
if (elementDescriptor == null) {
elementDescriptor = descriptor;
if (elementNamespace == null) {
elementNamespace = namespace;
}
}
}
}
curElement = curElement.getContext();
}
final Set<XmlNSDescriptor> visited = new HashSet<>();
final XmlExtension extension = XmlExtension.getExtension(element.getContainingFile());
final ArrayList<XmlElementDescriptor> variants = new ArrayList<>();
for (final String namespace : namespaces) {
final int initialSize = variants.size();
processVariantsInNamespace(namespace, element, variants, elementDescriptor, elementNamespace, descriptorsMap, visited, context instanceof XmlTag ? (XmlTag) context : element, extension);
if (nsInfo != null) {
for (int i = initialSize; i < variants.size(); i++) {
XmlElementDescriptor descriptor = variants.get(i);
nsInfo.add(descriptor instanceof XmlElementDescriptorImpl && !(descriptor instanceof RelaxedHtmlFromSchemaElementDescriptor) ? ((XmlElementDescriptorImpl) descriptor).getNamespaceByContext(element) : namespace);
}
}
}
final boolean hasPrefix = StringUtil.isNotEmpty(element.getNamespacePrefix());
return ContainerUtil.filter(variants, descriptor -> {
if (descriptor instanceof AnyXmlElementDescriptor) {
return false;
} else if (hasPrefix && descriptor instanceof XmlElementDescriptorImpl && !namespaces.contains(((XmlElementDescriptorImpl) descriptor).getNamespace())) {
return false;
}
return true;
});
}
use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-plugins by JetBrains.
the class AngularJSTagDescriptorsProvider method getDescriptor.
@Nullable
@Override
public XmlElementDescriptor getDescriptor(XmlTag xmlTag) {
final Project project = xmlTag.getProject();
if (!(xmlTag instanceof HtmlTag && AngularIndexUtil.hasAngularJS(project)))
return null;
final String tagName = xmlTag.getName();
final String directiveName = DirectiveUtil.normalizeAttributeName(tagName);
final XmlNSDescriptor nsDescriptor = xmlTag.getNSDescriptor(xmlTag.getNamespace(), false);
final XmlElementDescriptor descriptor = nsDescriptor != null ? nsDescriptor.getElementDescriptor(xmlTag) : null;
if (descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor)) {
return null;
}
if ((NG_CONTAINER.equals(directiveName) || NG_CONTENT.equals(directiveName) || NG_TEMPLATE.equals(directiveName)) && AngularIndexUtil.hasAngularJS2(project)) {
return new AngularJSTagDescriptor(directiveName, createDirective(xmlTag, directiveName));
}
JSImplicitElement directive = DirectiveUtil.getTagDirective(directiveName, project);
if (DirectiveUtil.isAngular2Directive(directive) && !directive.getName().equals(tagName)) {
// we've found directive via normalized name for Angular, it should not work
directive = null;
}
if (directive == null && !tagName.equals(directiveName) && AngularIndexUtil.hasAngularJS2(project)) {
directive = DirectiveUtil.getTagDirective(tagName, project);
if (!DirectiveUtil.isAngular2Directive(directive))
directive = null;
}
return directive != null ? new AngularJSTagDescriptor(directiveName, directive) : null;
}
use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class AbstractDomChildrenDescriptor method getElementsDescriptors.
@Override
public XmlElementDescriptor[] getElementsDescriptors(final XmlTag context) {
final DomElement domElement = myManager.getDomElement(context);
if (domElement == null)
return EMPTY_ARRAY;
List<XmlElementDescriptor> xmlElementDescriptors = new ArrayList<>();
for (DomCollectionChildDescription childrenDescription : domElement.getGenericInfo().getCollectionChildrenDescriptions()) {
xmlElementDescriptors.add(new DomElementXmlDescriptor(childrenDescription, myManager));
}
for (DomFixedChildDescription childrenDescription : domElement.getGenericInfo().getFixedChildrenDescriptions()) {
xmlElementDescriptors.add(new DomElementXmlDescriptor(childrenDescription, myManager));
}
final List<? extends CustomDomChildrenDescription> customs = domElement.getGenericInfo().getCustomNameChildrenDescription();
for (final CustomDomChildrenDescription custom : customs) {
final CustomDomChildrenDescription.TagNameDescriptor tagNameDescriptor = custom.getTagNameDescriptor();
if (tagNameDescriptor == null)
continue;
final XmlTag xmlTag = domElement.getXmlTag();
for (final EvaluatedXmlName name : tagNameDescriptor.getCompletionVariants(domElement)) {
AbstractDomChildrenDescriptor descriptor = new AbstractDomChildrenDescriptor(myManager) {
@Override
public String getDefaultName() {
final String ns = xmlTag != null ? name.getNamespace(xmlTag, (XmlFile) xmlTag.getContainingFile()) : null;
if (ns != null) {
final String prefix = xmlTag.getPrefixByNamespace(ns);
if (prefix != null) {
return prefix + ":" + name.getXmlName().getLocalName();
}
}
return name.getXmlName().getLocalName();
}
@Override
@Nullable
public PsiElement getDeclaration() {
final PomTarget target = tagNameDescriptor.findDeclaration(domElement, name);
return target == null ? null : PomService.convertToPsi(context.getProject(), target);
}
};
xmlElementDescriptors.add(descriptor);
}
xmlElementDescriptors.add(new AnyXmlElementDescriptor(this, getNSDescriptor()));
}
return xmlElementDescriptors.toArray(new XmlElementDescriptor[xmlElementDescriptors.size()]);
}
use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class RngNsDescriptor method getElementDescriptor.
@Override
@Nullable
public XmlElementDescriptor getElementDescriptor(@NotNull XmlTag tag) {
if (myPattern == null) {
return null;
}
XmlTag _tag = tag;
final LinkedList<XmlTag> chain = new LinkedList<>();
while (_tag != null) {
chain.addFirst(_tag);
_tag = _tag.getParentTag();
}
XmlElementDescriptor desc;
do {
desc = findRootDescriptor(chain.removeFirst());
} while (desc == null && chain.size() > 0);
if (desc != null) {
for (XmlTag xmlTag : chain) {
desc = desc.getElementDescriptor(xmlTag, xmlTag.getParentTag());
if (desc == null) {
break;
}
}
}
if (desc == null || desc instanceof AnyXmlElementDescriptor) {
return findRootDescriptor(tag);
}
return desc;
}
use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class RelaxedHtmlFromRngNSDescriptor method getElementDescriptor.
@Override
public XmlElementDescriptor getElementDescriptor(@NotNull XmlTag tag) {
XmlElementDescriptor elementDescriptor = super.getElementDescriptor(tag);
if (LOG.isDebugEnabled()) {
LOG.debug("Descriptor from rng for tag " + tag.getName() + " is " + (elementDescriptor != null ? elementDescriptor.getClass().getCanonicalName() : "NULL"));
}
String namespace;
if (elementDescriptor == null && !((namespace = tag.getNamespace()).equals(XmlUtil.XHTML_URI))) {
return new AnyXmlElementDescriptor(null, XmlUtil.HTML_URI.equals(namespace) ? this : tag.getNSDescriptor(tag.getNamespace(), true));
}
return elementDescriptor;
}
Aggregations