Search in sources :

Example 26 with Result

use of com.intellij.openapi.application.Result 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 27 with Result

use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.

the class TreeIncrementalUpdateTest method testRenameCollectionTag.

public void testRenameCollectionTag() throws Throwable {
    final MyElement rootElement = createPhysicalElement("<?xml version='1.0' encoding='UTF-8'?>\n" + "<a>\n" + " <boy>\n" + " </boy>\n" + " <girl/>\n" + "</a>");
    myCallRegistry.clear();
    assertEquals(1, rootElement.getBoys().size());
    assertEquals(1, rootElement.getGirls().size());
    final MyElement oldBoy = rootElement.getBoys().get(0);
    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.getGirls().get(0).undefine();
            final Document document = getDocument(DomUtil.getFile(rootElement));
            PsiDocumentManager.getInstance(getProject()).doPostponedOperationsAndUnblockDocument(document);
            document.replaceString(offset + 1, offset + 1 + "boy".length(), "girl");
            commitDocument(document);
        }
    }.execute();
    assertFalse(oldBoy.isValid());
    assertEquals(0, rootElement.getBoys().size());
    assertEquals(1, rootElement.getGirls().size());
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            final Document document = getDocument(DomUtil.getFile(rootElement));
            document.replaceString(endoffset - "boy".length(), endoffset, "girl");
            commitDocument(document);
        }
    }.execute();
    assertEquals(0, rootElement.getBoys().size());
    assertEquals(1, rootElement.getGirls().size());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Document(com.intellij.openapi.editor.Document) XmlTag(com.intellij.psi.xml.XmlTag) Result(com.intellij.openapi.application.Result)

Example 28 with Result

use of com.intellij.openapi.application.Result 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 29 with Result

use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.

the class TreeIncrementalUpdateTest method testAddFixedElement.

public void testAddFixedElement() throws Throwable {
    final MyElement element = createPhysicalElement("<a>" + "<child/>" + "<child><child/></child>" + "<child/></a>");
    final MyElement child = element.getChild();
    final MyElement child2 = element.getChild2();
    final XmlTag leafTag = child2.getChild().getXmlTag();
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            element.getXmlTag().addAfter(createTag("<child/>"), child.getXmlTag());
        }
    }.execute();
    assertNoCache(leafTag);
    final XmlTag[] subTags = element.getXmlTag().getSubTags();
    assertFalse(child2.isValid());
    assertEquals(child, element.getChild());
    assertFalse(child2.equals(element.getChild2()));
    assertCached(child, subTags[0]);
    assertNoCache(subTags[2]);
    assertNoCache(subTags[3]);
    putExpected(new DomEvent(element, false));
    putExpected(new DomEvent(element, false));
    assertResultsAndClear();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlTag(com.intellij.psi.xml.XmlTag) Result(com.intellij.openapi.application.Result) DomEvent(com.intellij.util.xml.events.DomEvent)

Example 30 with Result

use of com.intellij.openapi.application.Result in project intellij-community by JetBrains.

the class TreeIncrementalUpdateTest method testRemoveAttributeParent.

public void testRemoveAttributeParent() throws Throwable {
    final XmlFile file = (XmlFile) createFile("file.xml", "<?xml version='1.0' encoding='UTF-8'?>\n" + "<!DOCTYPE ejb-jar PUBLIC \"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN\" \"http://java.sun.com/dtd/ejb-jar_2_0.dtd\">\n" + "<a>\n" + " <child-element xxx=\"239\"/>\n" + "</a>");
    final DomFileElementImpl<MyElement> fileElement = getDomManager().getFileElement(file, MyElement.class, "a");
    myCallRegistry.clear();
    final MyElement rootElement = fileElement.getRootElement();
    final MyElement oldLeaf = rootElement.getChildElements().get(0);
    final GenericAttributeValue<String> xxx = oldLeaf.getXxx();
    final XmlTag oldLeafTag = oldLeaf.getXmlTag();
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            oldLeafTag.delete();
        }
    }.execute();
    assertFalse(oldLeaf.isValid());
    assertFalse(xxx.isValid());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlFile(com.intellij.psi.xml.XmlFile) XmlTag(com.intellij.psi.xml.XmlTag) Result(com.intellij.openapi.application.Result)

Aggregations

Result (com.intellij.openapi.application.Result)278 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)177 NotNull (org.jetbrains.annotations.NotNull)111 WriteAction (com.intellij.openapi.application.WriteAction)87 VirtualFile (com.intellij.openapi.vfs.VirtualFile)76 Project (com.intellij.openapi.project.Project)55 File (java.io.File)30 Document (com.intellij.openapi.editor.Document)28 Module (com.intellij.openapi.module.Module)28 XmlFile (com.intellij.psi.xml.XmlFile)28 IOException (java.io.IOException)26 PsiFile (com.intellij.psi.PsiFile)25 XmlTag (com.intellij.psi.xml.XmlTag)24 Nullable (org.jetbrains.annotations.Nullable)16 ArrayList (java.util.ArrayList)15 ReadAction (com.intellij.openapi.application.ReadAction)14 Editor (com.intellij.openapi.editor.Editor)12 NlModel (com.android.tools.idea.uibuilder.model.NlModel)11 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)10 TextRange (com.intellij.openapi.util.TextRange)10