Search in sources :

Example 66 with XmlFile

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);
        }
    });
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XmlRecursiveElementVisitor(com.intellij.psi.XmlRecursiveElementVisitor) THashMap(gnu.trove.THashMap) Nullable(org.jetbrains.annotations.Nullable) XmlTag(com.intellij.psi.xml.XmlTag)

Example 67 with XmlFile

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);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) Nullable(org.jetbrains.annotations.Nullable)

Example 68 with XmlFile

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;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 69 with XmlFile

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());
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 70 with XmlFile

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());
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlFile (com.intellij.psi.xml.XmlFile)409 XmlTag (com.intellij.psi.xml.XmlTag)155 PsiFile (com.intellij.psi.PsiFile)121 VirtualFile (com.intellij.openapi.vfs.VirtualFile)102 Nullable (org.jetbrains.annotations.Nullable)74 Project (com.intellij.openapi.project.Project)69 NotNull (org.jetbrains.annotations.NotNull)66 PsiElement (com.intellij.psi.PsiElement)64 XmlAttribute (com.intellij.psi.xml.XmlAttribute)39 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)34 Module (com.intellij.openapi.module.Module)34 XmlDocument (com.intellij.psi.xml.XmlDocument)32 Result (com.intellij.openapi.application.Result)28 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)23 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)22 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)21 ArrayList (java.util.ArrayList)20 Document (com.intellij.openapi.editor.Document)19 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)18 Editor (com.intellij.openapi.editor.Editor)15