use of com.intellij.xml.impl.schema.XmlNSDescriptorImpl in project intellij-community by JetBrains.
the class MavenDomElementDescriptorHolder method getDescriptor.
@Nullable
public XmlElementDescriptor getDescriptor(@NotNull XmlTag tag) {
FileKind kind = getFileKind(tag.getContainingFile());
if (kind == null)
return null;
XmlNSDescriptorImpl desc;
synchronized (this) {
desc = tryGetOrCreateDescriptor(kind);
if (desc == null)
return null;
}
LOG.assertTrue(tag.isValid());
LOG.assertTrue(desc.isValid());
return desc.getElementDescriptor(tag.getName(), desc.getDefaultNamespace());
}
use of com.intellij.xml.impl.schema.XmlNSDescriptorImpl in project intellij-community by JetBrains.
the class CreateXmlElementIntentionAction method isAvailable.
@Override
public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile file) {
if (!myIsAvailableEvaluated) {
final XmlTag tag = PsiTreeUtil.getParentOfType(myRef.getElement(), XmlTag.class);
if (tag != null) {
final XmlNSDescriptorImpl descriptor = myRef.getDescriptor(tag, myRef.getCanonicalText(), new boolean[1]);
if (descriptor != null && descriptor.getDescriptorFile() != null && descriptor.getDescriptorFile().isWritable()) {
myTargetFile = descriptor.getDescriptorFile();
}
}
myIsAvailableEvaluated = true;
}
return myTargetFile != null;
}
use of com.intellij.xml.impl.schema.XmlNSDescriptorImpl 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.xml.impl.schema.XmlNSDescriptorImpl in project intellij-community by JetBrains.
the class TypeOrElementOrAttributeReference method getVariants.
public static Object[] getVariants(XmlTag tag, ReferenceType type, String prefix) {
String[] tagNames = null;
switch(type) {
case GroupReference:
tagNames = new String[] { SchemaReferencesProvider.GROUP_TAG_NAME };
break;
case AttributeGroupReference:
tagNames = new String[] { SchemaReferencesProvider.ATTRIBUTE_GROUP_TAG_NAME };
break;
case AttributeReference:
tagNames = new String[] { SchemaReferencesProvider.ATTRIBUTE_TAG_NAME };
break;
case ElementReference:
tagNames = new String[] { SchemaReferencesProvider.ELEMENT_TAG_NAME };
break;
case TypeReference:
tagNames = new String[] { SchemaReferencesProvider.SIMPLE_TYPE_TAG_NAME, SchemaReferencesProvider.COMPLEX_TYPE_TAG_NAME };
break;
}
final XmlDocument document = ((XmlFile) tag.getContainingFile()).getDocument();
if (document == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final XmlTag rootTag = document.getRootTag();
String ourNamespace = rootTag != null ? rootTag.getAttributeValue(TARGET_NAMESPACE) : "";
if (ourNamespace == null)
ourNamespace = "";
CompletionProcessor processor = new CompletionProcessor(tag, prefix);
for (String namespace : tag.knownNamespaces()) {
if (ourNamespace.equals(namespace))
continue;
final XmlNSDescriptor nsDescriptor = tag.getNSDescriptor(namespace, true);
if (nsDescriptor instanceof XmlNSDescriptorImpl) {
processNamespace(namespace, processor, (XmlNSDescriptorImpl) nsDescriptor, tagNames);
}
}
XmlNSDescriptor nsDescriptor = (XmlNSDescriptor) document.getMetaData();
if (nsDescriptor instanceof XmlNSDescriptorImpl) {
processNamespace(ourNamespace, processor, (XmlNSDescriptorImpl) nsDescriptor, tagNames);
}
return ArrayUtil.toStringArray(processor.myElements);
}
use of com.intellij.xml.impl.schema.XmlNSDescriptorImpl in project intellij-community by JetBrains.
the class TypeOrElementOrAttributeReference method resolveInner.
private PsiElement resolveInner() {
final XmlTag tag = PsiTreeUtil.getContextOfType(myElement, XmlTag.class, false);
if (tag == null)
return PsiUtilCore.NULL_PSI_ELEMENT;
String canonicalText = getCanonicalText();
boolean[] redefined = new boolean[1];
XmlNSDescriptorImpl nsDescriptor = getDescriptor(tag, canonicalText, redefined);
if (myType != null && nsDescriptor != null && nsDescriptor.getTag() != null) {
switch(myType) {
case GroupReference:
return nsDescriptor.findGroup(canonicalText);
case AttributeGroupReference:
return nsDescriptor.findAttributeGroup(canonicalText);
case ElementReference:
{
XmlElementDescriptor descriptor = nsDescriptor.getElementDescriptor(XmlUtil.findLocalNameByQualifiedName(canonicalText), getNamespace(tag, canonicalText), new HashSet<>(), true);
return descriptor != null ? descriptor.getDeclaration() : PsiUtilCore.NULL_PSI_ELEMENT;
}
case AttributeReference:
{
//final String prefixByQualifiedName = XmlUtil.findPrefixByQualifiedName(canonicalText);
final String localNameByQualifiedName = XmlUtil.findLocalNameByQualifiedName(canonicalText);
XmlAttributeDescriptor descriptor = nsDescriptor.getAttribute(localNameByQualifiedName, getNamespace(tag, canonicalText), tag);
if (descriptor != null)
return descriptor.getDeclaration();
return PsiUtilCore.NULL_PSI_ELEMENT;
}
case TypeReference:
{
TypeDescriptor typeDescriptor = redefined[0] ? nsDescriptor.findTypeDescriptor(XmlUtil.findLocalNameByQualifiedName(canonicalText), "") : nsDescriptor.getTypeDescriptor(canonicalText, tag);
if (typeDescriptor instanceof ComplexTypeDescriptor) {
return typeDescriptor.getDeclaration();
} else if (typeDescriptor != null) {
return myElement;
}
}
}
}
return PsiUtilCore.NULL_PSI_ELEMENT;
}
Aggregations