use of com.intellij.xml.impl.schema.XmlElementDescriptorImpl in project intellij-community by JetBrains.
the class XmlUtil method getSchemaSimpleContent.
@Nullable
public static XmlTag getSchemaSimpleContent(@NotNull XmlTag tag) {
XmlElementDescriptor descriptor = tag.getDescriptor();
if (descriptor instanceof XmlElementDescriptorImpl) {
final TypeDescriptor type = ((XmlElementDescriptorImpl) descriptor).getType(tag);
if (type instanceof ComplexTypeDescriptor) {
final XmlTag[] simpleContent = new XmlTag[1];
processXmlElements(((ComplexTypeDescriptor) type).getDeclaration(), new PsiElementProcessor() {
@Override
public boolean execute(@NotNull final PsiElement element) {
if (element instanceof XmlTag) {
final XmlTag tag = (XmlTag) element;
@NonNls final String s = ((XmlTag) element).getLocalName();
if ((s.equals(XSD_SIMPLE_CONTENT_TAG) || s.equals("restriction") && "string".equals(findLocalNameByQualifiedName(tag.getAttributeValue("base")))) && tag.getNamespace().equals(XML_SCHEMA_URI)) {
simpleContent[0] = tag;
return false;
}
}
return true;
}
}, true);
return simpleContent[0];
}
}
return null;
}
use of com.intellij.xml.impl.schema.XmlElementDescriptorImpl 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.XmlElementDescriptorImpl in project intellij-community by JetBrains.
the class XsltContextProviderBase method processElementDescriptors.
private static void processElementDescriptors(XmlElementDescriptor descriptor, XmlTag tag, ElementNames names, Set<XmlElementDescriptor> history, int depth) throws StopProcessingException {
if (!history.add(descriptor) || ++depth == 200) {
if (depth == 200) {
throw new StopProcessingException();
}
return;
}
final String namespace = descriptor instanceof XmlElementDescriptorImpl ? ((XmlElementDescriptorImpl) descriptor).getNamespace() : tag.getNamespace();
names.elementNames.add(new QName(namespace, descriptor.getName()));
final XmlAttributeDescriptor[] attributesDescriptors = descriptor.getAttributesDescriptors(null);
for (XmlAttributeDescriptor attributesDescriptor : attributesDescriptors) {
final String localPart = attributesDescriptor.getName();
if (!"xmlns".equals(localPart))
names.attributeNames.add(new QName(localPart));
}
final XmlElementDescriptor[] descriptors = descriptor.getElementsDescriptors(tag);
for (XmlElementDescriptor elem : descriptors) {
processElementDescriptors(elem, tag, names, history, depth);
}
}
use of com.intellij.xml.impl.schema.XmlElementDescriptorImpl in project intellij-community by JetBrains.
the class XmlHighlightingTest method testAnyAttributeNavigation.
public void testAnyAttributeNavigation() throws Exception {
configureByFiles(null, getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xml"), getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xsd"), getVirtualFile(BASE_PATH + "AnyAttributeNavigation/library.xsd"));
PsiReference at = getFile().findReferenceAt(getEditor().getCaretModel().getOffset());
XmlTag tag = PsiTreeUtil.getParentOfType(at.getElement(), XmlTag.class);
XmlElementDescriptorImpl descriptor = (XmlElementDescriptorImpl) tag.getDescriptor();
XmlAttributeDescriptor[] descriptors = descriptor.getAttributesDescriptors(tag);
System.out.println(Arrays.asList(descriptors));
doDoTest(true, false);
PsiElement resolve = at.resolve();
assertTrue(resolve instanceof XmlTag);
}
use of com.intellij.xml.impl.schema.XmlElementDescriptorImpl in project intellij-community by JetBrains.
the class XmlTagInsertHandler method addRequiredSubTags.
private static boolean addRequiredSubTags(Template template, XmlElementDescriptor descriptor, PsiFile file, XmlTag context) {
if (!WebEditorOptions.getInstance().isAutomaticallyInsertRequiredSubTags())
return false;
List<XmlElementDescriptor> requiredSubTags = GenerateXmlTagAction.getRequiredSubTags(descriptor);
if (!requiredSubTags.isEmpty()) {
template.addTextSegment(">");
template.setToReformat(true);
}
for (XmlElementDescriptor subTag : requiredSubTags) {
if (subTag == null) {
// placeholder for smart completion
template.addTextSegment("<");
template.addVariable(new MacroCallNode(new CompleteSmartMacro()), true);
continue;
}
String qname = subTag.getName();
if (subTag instanceof XmlElementDescriptorImpl) {
String prefixByNamespace = context.getPrefixByNamespace(((XmlElementDescriptorImpl) subTag).getNamespace());
if (StringUtil.isNotEmpty(prefixByNamespace)) {
qname = prefixByNamespace + ":" + subTag.getName();
}
}
template.addTextSegment("<" + qname);
addRequiredAttributes(subTag, null, template, file);
completeTagTail(template, subTag, file, context, false);
}
if (!requiredSubTags.isEmpty()) {
addTagEnd(template, descriptor, context);
}
return !requiredSubTags.isEmpty();
}
Aggregations