use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class MicrodataUtil method findScopesWithItemRef.
private static Map<String, XmlTag> findScopesWithItemRef(@Nullable final PsiFile file) {
if (!(file instanceof XmlFile))
return Collections.emptyMap();
return CachedValuesManager.getCachedValue(file, new CachedValueProvider<Map<String, XmlTag>>() {
@Nullable
@Override
public Result<Map<String, XmlTag>> compute() {
final Map<String, XmlTag> result = new THashMap<>();
file.accept(new XmlRecursiveElementVisitor() {
@Override
public void visitXmlTag(final XmlTag tag) {
super.visitXmlTag(tag);
XmlAttribute refAttr = tag.getAttribute(ITEM_REF);
if (refAttr != null && tag.getAttribute(ITEM_SCOPE) != null) {
getReferencesForAttributeValue(refAttr.getValueElement(), (t, v) -> {
result.put(t, tag);
return null;
});
}
}
});
return Result.create(result, file);
}
});
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class ExternalResourceManagerExImpl method getResourceLocation.
@Override
@Nullable
public PsiFile getResourceLocation(@NotNull @NonNls final String url, @NotNull final PsiFile baseFile, final String version) {
final XmlFile schema = XmlSchemaProvider.findSchema(url, baseFile);
if (schema != null) {
return schema;
}
final String location = getResourceLocation(url, version, baseFile.getProject());
return XmlUtil.findXmlFile(baseFile, location);
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class RngHrefConverter method fromString.
@Override
public XmlFile fromString(@Nullable @NonNls String s, ConvertContext context) {
if (s != null) {
final GenericAttributeValue<XmlFile> element = (GenericAttributeValue<XmlFile>) context.getInvocationElement();
final PsiReference[] references = createReferences(element, element.getXmlAttributeValue(), context);
if (references.length > 0) {
PsiElement result = references[references.length - 1].resolve();
if (result instanceof XmlFile) {
return (XmlFile) result;
}
}
}
return null;
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XmlInsightTest method testAttributeDescriptor2.
public void testAttributeDescriptor2() throws Exception {
XmlFile file = createFile("<root><a c='' a=''></a></root>");
XmlNSDescriptor descriptor = createDescriptor(file);
XmlTag rootTag = file.getDocument().getRootTag();
XmlElementDescriptor element = descriptor.getElementDescriptor(rootTag);
element = element.getElementsDescriptors(rootTag)[0];
XmlAttributeDescriptor[] attributes = element.getAttributesDescriptors(rootTag);
assertEquals("c", attributes[0].getName());
assertTrue(attributes[0].isRequired());
assertEquals("a", attributes[1].getName());
assertTrue(attributes[1].isRequired());
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XmlInsightTest method testAttributeDescriptor1.
public void testAttributeDescriptor1() throws Exception {
XmlFile file = createFile("<root><a attr1=''></a><a attr2='' attr1=''></a></root>");
XmlNSDescriptor descriptor = createDescriptor(file);
XmlTag rootTag = file.getDocument().getRootTag();
XmlElementDescriptor element = descriptor.getElementDescriptor(rootTag);
element = element.getElementsDescriptors(rootTag)[0];
XmlAttributeDescriptor[] attributes = element.getAttributesDescriptors(rootTag);
assertEquals("attr1", attributes[0].getName());
assertTrue(attributes[0].isRequired());
assertEquals("attr2", attributes[1].getName());
assertTrue(!attributes[1].isRequired());
}
Aggregations