use of com.intellij.xml.XmlElementDescriptor in project intellij-community by JetBrains.
the class MavenPropertyPsiReference method processSchema.
@Nullable
private <T> T processSchema(String schema, SchemaProcessor<T> processor) {
VirtualFile file = MavenSchemaProvider.getSchemaFile(schema);
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
if (!(psiFile instanceof XmlFile))
return null;
XmlFile xmlFile = (XmlFile) psiFile;
XmlDocument document = xmlFile.getDocument();
XmlNSDescriptor desc = (XmlNSDescriptor) document.getMetaData();
XmlElementDescriptor[] descriptors = desc.getRootElementsDescriptors(document);
return doProcessSchema(descriptors, null, processor, new THashSet<>());
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-community by JetBrains.
the class BaseDomElementNode method doGetChildren.
protected final SimpleNode[] doGetChildren(final DomElement element) {
if (!element.isValid())
return NO_CHILDREN;
List<SimpleNode> children = new ArrayList<>();
final XmlTag tag = element.getXmlTag();
if (tag != null && !(tag.getContainingFile() instanceof XmlFile))
return NO_CHILDREN;
final XmlElementDescriptor xmlElementDescriptor = tag == null ? null : tag.getDescriptor();
final XmlElementDescriptor[] xmlDescriptors = xmlElementDescriptor == null ? null : xmlElementDescriptor.getElementsDescriptors(tag);
for (DomFixedChildDescription description : element.getGenericInfo().getFixedChildrenDescriptions()) {
String childName = description.getXmlElementName();
if (xmlDescriptors != null) {
if (findDescriptor(xmlDescriptors, childName) == -1)
continue;
}
final List<? extends DomElement> values = description.getStableValues(element);
if (shouldBeShown(description.getType())) {
if (DomUtil.isGenericValueType(description.getType())) {
for (DomElement value : values) {
children.add(new GenericValueNode((GenericDomValue) value, this));
}
} else {
for (DomElement domElement : values) {
children.add(new BaseDomElementNode(domElement, myRootDomElement, this));
}
}
}
}
for (DomCollectionChildDescription description : element.getGenericInfo().getCollectionChildrenDescriptions()) {
if (shouldBeShown(description.getType())) {
DomElementsGroupNode groupNode = new DomElementsGroupNode(element, description, this, myRootDomElement);
if (isMarkedType(description.getType(), CONSOLIDATED_NODES_KEY)) {
Collections.addAll(children, groupNode.getChildren());
} else {
children.add(groupNode);
}
}
}
AbstractDomElementNode[] childrenNodes = children.toArray(new AbstractDomElementNode[children.size()]);
Comparator<AbstractDomElementNode> comparator = DomUtil.getFile(myDomElement).getUserData(COMPARATOR_KEY);
if (comparator == null) {
comparator = getDefaultComparator(element);
}
if (comparator != null) {
Arrays.sort(childrenNodes, comparator);
}
return childrenNodes;
}
use of com.intellij.xml.XmlElementDescriptor 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.XmlElementDescriptor in project intellij-community by JetBrains.
the class CompositeDescriptor method findElementDescriptor.
@Override
protected XmlElementDescriptor findElementDescriptor(XmlTag childTag) {
final List<DElementPattern> patterns = new ArrayList<>();
for (DElementPattern pattern : myPatterns) {
patterns.addAll(ChildElementFinder.find(2, pattern));
}
// TODO: filter out impossible variants:
/*
while this needs both variants of <choice>-children
<element><choice><caret>
this does not, because <choice> inside <choice> is unambiguous:
<element><choice><data type="string" /><choice><caret>
*/
final XmlElementDescriptor d = myNsDescriptor.findDescriptor(childTag, patterns);
if (d != null) {
return d;
}
return NULL;
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-community by JetBrains.
the class CompositeDescriptor method getElementsDescriptors.
@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
final List<XmlElementDescriptor> descriptors = new ArrayList<>(Arrays.asList(super.getElementsDescriptors(context)));
for (DElementPattern pattern : myPatterns) {
final List<DElementPattern> list = ChildElementFinder.find(2, pattern);
descriptors.addAll(Arrays.asList(myNsDescriptor.convertElementDescriptors(list)));
}
return descriptors.toArray(new XmlElementDescriptor[descriptors.size()]);
}
Aggregations