use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class Xsd2InstanceUtils method addVariantsFromRootTag.
public static List<String> addVariantsFromRootTag(XmlTag rootTag) {
PsiMetaData metaData = rootTag.getMetaData();
if (metaData instanceof XmlNSDescriptorImpl) {
XmlNSDescriptorImpl nsDescriptor = (XmlNSDescriptorImpl) metaData;
List<String> elementDescriptors = new ArrayList<>();
XmlElementDescriptor[] rootElementsDescriptors = nsDescriptor.getRootElementsDescriptors(PsiTreeUtil.getParentOfType(rootTag, XmlDocument.class));
for (XmlElementDescriptor e : rootElementsDescriptors) {
elementDescriptors.add(e.getName());
}
return elementDescriptors;
}
return Collections.emptyList();
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class HtmlDocumentationProvider method findDocumentationDescriptor.
private static EntityDescriptor findDocumentationDescriptor(PsiElement element, XmlTag context) {
boolean isTag = true;
PsiElement nameElement = null;
String key = null;
if (element instanceof XmlElementDecl) {
nameElement = ((XmlElementDecl) element).getNameElement();
} else if (element instanceof XmlAttributeDecl) {
nameElement = ((XmlAttributeDecl) element).getNameElement();
isTag = false;
} else if (element instanceof XmlTag) {
final XmlTag xmlTag = ((XmlTag) element);
final PsiMetaData metaData = xmlTag.getMetaData();
key = (metaData != null) ? metaData.getName() : null;
isTag = xmlTag.getLocalName().equals(ELEMENT_ELEMENT_NAME);
} else if (element.getParent() instanceof XmlAttributeValue) {
isTag = false;
key = ((XmlAttribute) element.getParent().getParent()).getName();
} else if (element instanceof XmlAttributeValue) {
isTag = false;
final XmlAttribute xmlAttribute = (XmlAttribute) element.getParent();
key = xmlAttribute.getName();
} else if (element instanceof XmlAttribute) {
final XmlAttribute xmlAttribute = (XmlAttribute) element;
isTag = false;
key = xmlAttribute.getName();
} else if (element instanceof XmlElement) {
nameElement = element;
isTag = !(element.getParent() instanceof XmlAttribute);
} else {
nameElement = element;
if (context != null) {
String text = element.getText();
isTag = text != null && text.startsWith(context.getName());
}
}
if (nameElement != null) {
key = nameElement.getText();
}
key = StringUtil.notNullize(key).toLowerCase(Locale.US);
int dotIndex = key.indexOf('.');
if (dotIndex > 0) {
key = key.substring(0, dotIndex);
}
if (isTag) {
return HtmlDescriptorsTable.getTagDescriptor(key);
} else {
return getDescriptor(key, context);
}
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class XmlNSDescriptorImpl method getElementDescriptor.
@Nullable
public XmlElementDescriptor getElementDescriptor(String localName, String namespace, Set<XmlNSDescriptorImpl> visited, boolean reference) {
if (visited.contains(this))
return null;
final QNameKey pair = new QNameKey(namespace, localName);
final CachedValue<XmlElementDescriptor> descriptor = myDescriptorsMap.get(pair);
if (descriptor != null) {
final XmlElementDescriptor value = descriptor.getValue();
if (value == null || value.getDeclaration().isValid())
return value;
}
final XmlTag rootTag = myTag;
if (rootTag == null)
return null;
XmlTag[] tags = rootTag.getSubTags();
visited.add(this);
LOG.assertTrue(rootTag.isValid());
for (final XmlTag tag : tags) {
if (equalsToSchemaName(tag, ELEMENT_TAG_NAME)) {
String name = tag.getAttributeValue("name");
if (name != null) {
if (checkElementNameEquivalence(localName, namespace, name, tag)) {
final CachedValue<XmlElementDescriptor> cachedValue = CachedValuesManager.getManager(tag.getProject()).createCachedValue(() -> {
final String name1 = tag.getAttributeValue("name");
if (name1 != null && !name1.equals(pair.second)) {
myDescriptorsMap.remove(pair);
return new CachedValueProvider.Result<>(null, PsiModificationTracker.MODIFICATION_COUNT);
}
final XmlElementDescriptor xmlElementDescriptor = createElementDescriptor(tag);
return new CachedValueProvider.Result<>(xmlElementDescriptor, xmlElementDescriptor.getDependences());
}, false);
myDescriptorsMap.put(pair, cachedValue);
return cachedValue.getValue();
}
}
} else if (equalsToSchemaName(tag, INCLUDE_TAG_NAME) || (reference && equalsToSchemaName(tag, IMPORT_TAG_NAME) && (namespace.equals(tag.getAttributeValue("namespace")) || namespace.length() == 0 && tag.getAttributeValue("namespace") == null))) {
final String schemaLocation = tag.getAttributeValue("schemaLocation");
if (schemaLocation != null) {
final XmlFile xmlFile = XmlUtil.findNamespace(rootTag.getContainingFile(), schemaLocation);
if (xmlFile != null) {
final XmlDocument includedDocument = xmlFile.getDocument();
if (includedDocument != null) {
final PsiMetaData data = includedDocument.getMetaData();
if (data instanceof XmlNSDescriptorImpl) {
final XmlElementDescriptor elementDescriptor = ((XmlNSDescriptorImpl) data).getElementDescriptor(localName, namespace, visited, reference);
if (elementDescriptor != null) {
return elementDescriptor;
}
}
}
}
}
} else if (equalsToSchemaName(tag, REDEFINE_TAG_NAME)) {
final XmlNSDescriptorImpl nsDescriptor = getRedefinedElementDescriptor(tag);
if (nsDescriptor != null) {
final XmlElementDescriptor xmlElementDescriptor = nsDescriptor.getElementDescriptor(localName, namespace, visited, reference);
if (xmlElementDescriptor instanceof XmlElementDescriptorImpl) {
return new RedefinedElementDescriptor((XmlElementDescriptorImpl) xmlElementDescriptor, this);
}
}
}
}
return null;
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class XmlNSDescriptorImpl method getRedefinedElementDescriptor.
public static XmlNSDescriptorImpl getRedefinedElementDescriptor(final XmlTag parentTag) {
XmlFile file = getRedefinedElementDescriptorFile(parentTag);
if (file != null) {
final XmlDocument document = file.getDocument();
final PsiMetaData metaData = document != null ? document.getMetaData() : null;
if (metaData instanceof XmlNSDescriptorImpl)
return (XmlNSDescriptorImpl) metaData;
}
return null;
}
use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.
the class XmlNSDescriptorImpl method getAttributeImpl.
@Nullable
private XmlAttributeDescriptor getAttributeImpl(String localName, String namespace, @Nullable Set<XmlTag> visited) {
if (myTag == null)
return null;
XmlNSDescriptor nsDescriptor = myTag.getNSDescriptor(namespace, true);
if (nsDescriptor != this && nsDescriptor instanceof XmlNSDescriptorImpl) {
return ((XmlNSDescriptorImpl) nsDescriptor).getAttributeImpl(localName, namespace, visited);
}
if (visited == null)
visited = new HashSet<>(1);
else if (visited.contains(myTag))
return null;
visited.add(myTag);
XmlTag[] tags = myTag.getSubTags();
for (XmlTag tag : tags) {
if (equalsToSchemaName(tag, ATTRIBUTE_TAG_NAME)) {
String name = tag.getAttributeValue("name");
if (name != null) {
if (checkElementNameEquivalence(localName, namespace, name, tag)) {
return createAttributeDescriptor(tag);
}
}
} else if (equalsToSchemaName(tag, INCLUDE_TAG_NAME) || (equalsToSchemaName(tag, IMPORT_TAG_NAME) && namespace.equals(tag.getAttributeValue("namespace")))) {
final String schemaLocation = tag.getAttributeValue("schemaLocation");
if (schemaLocation != null) {
final XmlFile xmlFile = XmlUtil.findNamespace(myTag.getContainingFile(), schemaLocation);
if (xmlFile != null) {
final XmlDocument includedDocument = xmlFile.getDocument();
if (includedDocument != null) {
final PsiMetaData data = includedDocument.getMetaData();
if (data instanceof XmlNSDescriptorImpl) {
final XmlAttributeDescriptor attributeDescriptor = ((XmlNSDescriptorImpl) data).getAttributeImpl(localName, namespace, visited);
if (attributeDescriptor != null) {
final CachedValue<XmlAttributeDescriptor> value = CachedValuesManager.getManager(includedDocument.getProject()).createCachedValue(() -> {
Object[] deps = attributeDescriptor.getDependences();
if (deps.length == 0) {
LOG.error(attributeDescriptor + " (" + attributeDescriptor.getClass() + ") returned no dependencies");
}
return new CachedValueProvider.Result<>(attributeDescriptor, deps);
}, false);
return value.getValue();
}
}
}
}
}
}
}
return null;
}
Aggregations