Search in sources :

Example 56 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class DomPerformanceTest method testDontParseNamespacedDomFiles.

public void testDontParseNamespacedDomFiles() throws Exception {
    getDomManager().registerFileDescription(new DomFileDescription(MyNamespacedElement.class, "foo") {

        @Override
        protected void initializeFileDescription() {
            registerNamespacePolicy("project", "project");
        }
    }, getTestRootDisposable());
    XmlFile file = (XmlFile) createFile("a.xml", "<foo xmlns=\"project\"/>");
    assertFalse(file.getNode().isParsed());
    assertNotNull(DomManager.getDomManager(getProject()).getFileElement(file, MyNamespacedElement.class));
    file = (XmlFile) createFile("a.xml", "<foo xmlns=\"project2\"/>");
    assertFalse(file.getNode().isParsed());
    assertNull(DomManager.getDomManager(getProject()).getFileElement(file, MyNamespacedElement.class));
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile)

Example 57 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class DomPerformanceTest method testShouldntParseNonDomFiles.

public void testShouldntParseNonDomFiles() throws Throwable {
    for (int i = 0; i < 420; i++) {
        getDomManager().registerFileDescription(new DomFileDescription(MyChildElement.class, "foo") {

            @Override
            public boolean isMyFile(@NotNull final XmlFile file, final Module module) {
                fail();
                return super.isMyFile(file, module);
            }
        }, getTestRootDisposable());
        getDomManager().registerFileDescription(new DomFileDescription(MyChildElement.class, "bar") {

            @Override
            public boolean isMyFile(@NotNull final XmlFile file, final Module module) {
                fail();
                return super.isMyFile(file, module);
            }
        }, getTestRootDisposable());
    }
    getDomManager().createMockElement(MyChildElement.class, null, true);
    @NotNull final VirtualFile virtualFile = createFile("a.xml", "").getVirtualFile();
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(virtualFile.getOutputStream(this)));
            writer.write("<root>\n");
            for (int i = 0; i < 23942; i++) {
                writer.write("<bar/>\n");
            }
            writer.write("</root>");
            writer.close();
            virtualFile.refresh(false, false);
        }
    }.execute();
    ((PsiManagerImpl) getPsiManager()).getFileManager().cleanupForNextTest();
    final XmlFile file = (XmlFile) getPsiManager().findFile(virtualFile);
    assertFalse(file.getNode().isParsed());
    assertTrue(StringUtil.isNotEmpty(file.getText()));
    PlatformTestUtil.startPerformanceTest("", 100, () -> assertNull(getDomManager().getFileElement(file))).cpuBound().useLegacyScaling().assertTiming();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlFile(com.intellij.psi.xml.XmlFile) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) BufferedWriter(java.io.BufferedWriter) OutputStreamWriter(java.io.OutputStreamWriter) Module(com.intellij.openapi.module.Module)

Example 58 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class DomSaxParserTest method assertData.

private void assertData(final String start, @Nullable final String localName, @Nullable String namespace, @Nullable String publicId, @Nullable String systemId) {
    XmlFileHeader expected = new XmlFileHeader(localName, namespace, publicId, systemId);
    XmlFile file = createXmlFile(start);
    assert !file.getNode().isParsed();
    assertEquals(expected, DomService.getInstance().getXmlFileHeader(file));
    ensureParsed(file);
    assert file.getNode().isParsed();
    assertEquals(expected, DomService.getInstance().getXmlFileHeader(file));
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile)

Example 59 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class TreeIncrementalUpdateTest method testRenameFixedTag.

public void testRenameFixedTag() throws Throwable {
    final XmlFile file = (XmlFile) createFile("file.xml", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<a>\n" + " <aboy>\n" + " </aboy>\n" + " <agirl/>\n" + "</a>");
    final DomFileElementImpl<MyElement> fileElement = getDomManager().getFileElement(file, MyElement.class, "a");
    myCallRegistry.clear();
    final MyElement rootElement = fileElement.getRootElement();
    assertNotNull(rootElement.getAboy().getXmlElement());
    assertNotNull(rootElement.getAgirl().getXmlElement());
    final MyElement oldBoy = rootElement.getAboy();
    final XmlTag tag = oldBoy.getXmlTag();
    assertNotNull(tag);
    final int offset = tag.getTextOffset();
    final int endoffset = offset + tag.getTextLength();
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            rootElement.getAgirl().undefine();
            final Document document = getDocument(file);
            PsiDocumentManager.getInstance(getProject()).doPostponedOperationsAndUnblockDocument(document);
            document.replaceString(offset + 1, offset + 1 + "aboy".length(), "agirl");
            commitDocument(document);
        }
    }.execute();
    assertFalse(oldBoy.isValid());
    assertNull(rootElement.getAboy().getXmlElement());
    assertNotNull(rootElement.getAgirl().getXmlElement());
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            final Document document = getDocument(file);
            document.replaceString(endoffset - "aboy".length(), endoffset, "agirl");
            commitDocument(document);
        }
    }.execute();
    assertNull(rootElement.getAboy().getXmlElement());
    assertNotNull(rootElement.getAgirl().getXmlElement());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlFile(com.intellij.psi.xml.XmlFile) Document(com.intellij.openapi.editor.Document) XmlTag(com.intellij.psi.xml.XmlTag) Result(com.intellij.openapi.application.Result)

Example 60 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class TreeIncrementalUpdateTest method testRootTagAppearsLater.

public void testRootTagAppearsLater() throws Throwable {
    final XmlFile file = createXmlFile("");
    final DomFileElementImpl<MyElement> fileElement = getDomManager().getFileElement(file, MyElement.class, "root");
    myCallRegistry.clear();
    assertNull(fileElement.getRootElement().getXmlTag());
    file.getDocument().replace(createXmlFile("<root/>").getDocument());
    final XmlTag rootTag = fileElement.getRootTag();
    assertEquals(rootTag, file.getDocument().getRootTag());
    putExpected(new DomEvent(fileElement.getRootElement(), false));
    assertResultsAndClear();
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlTag(com.intellij.psi.xml.XmlTag) DomEvent(com.intellij.util.xml.events.DomEvent)

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