Search in sources :

Example 16 with WriteCommandAction

use of com.intellij.openapi.command.WriteCommandAction in project intellij-community by JetBrains.

the class PySmartEnterTest method doTest.

public void doTest() {
    myFixture.configureByFile("codeInsight/smartEnter/" + getTestName(true) + ".py");
    final List<SmartEnterProcessor> processors = getSmartProcessors(PythonLanguage.getInstance());
    new WriteCommandAction(myFixture.getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            final Editor editor = myFixture.getEditor();
            for (SmartEnterProcessor processor : processors) {
                processor.process(myFixture.getProject(), editor, myFixture.getFile());
            }
        }
    }.execute();
    myFixture.checkResultByFile("codeInsight/smartEnter/" + getTestName(true) + "_after.py", true);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Editor(com.intellij.openapi.editor.Editor) SmartEnterProcessor(com.intellij.codeInsight.editorActions.smartEnter.SmartEnterProcessor) Result(com.intellij.openapi.application.Result)

Example 17 with WriteCommandAction

use of com.intellij.openapi.command.WriteCommandAction in project intellij-community by JetBrains.

the class TreeIncrementalUpdateTest method testInvalidateParent.

public void testInvalidateParent() throws Throwable {
    final MyElement root = getDomManager().createMockElement(MyElement.class, null, true);
    new WriteCommandAction<MyElement>(getProject()) {

        @Override
        protected void run(@NotNull Result<MyElement> result) throws Throwable {
            root.getChild().ensureTagExists();
            root.getChild2().ensureTagExists();
            final MyElement element = root.addChildElement().getChild();
            result.setResult(element);
            element.ensureTagExists().getValue().setText("abc");
            root.addChildElement();
            root.addChildElement();
        }
    }.execute().getResultObject();
    assertTrue(root.isValid());
    final MyElement element = root.getChildElements().get(0).getChild();
    assertTrue(element.isValid());
    final MyElement child = element.getChild();
    final MyElement genericValue = child.getChild();
    new WriteCommandAction(getProject()) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            final Document document = getDocument(DomUtil.getFile(element));
            final TextRange range = element.getXmlTag().getTextRange();
            document.replaceString(range.getStartOffset(), range.getEndOffset(), "");
            commitDocument(document);
        }
    }.execute();
    assertFalse(genericValue.isValid());
    assertFalse(child.isValid());
    assertFalse(element.isValid());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 18 with WriteCommandAction

use of com.intellij.openapi.command.WriteCommandAction 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 19 with WriteCommandAction

use of com.intellij.openapi.command.WriteCommandAction 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 20 with WriteCommandAction

use of com.intellij.openapi.command.WriteCommandAction 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)

Aggregations

WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)176 Result (com.intellij.openapi.application.Result)175 NotNull (org.jetbrains.annotations.NotNull)62 Project (com.intellij.openapi.project.Project)45 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 XmlFile (com.intellij.psi.xml.XmlFile)28 XmlTag (com.intellij.psi.xml.XmlTag)23 Document (com.intellij.openapi.editor.Document)22 PsiFile (com.intellij.psi.PsiFile)16 Module (com.intellij.openapi.module.Module)14 Nullable (org.jetbrains.annotations.Nullable)12 NlModel (com.android.tools.idea.uibuilder.model.NlModel)11 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)10 Editor (com.intellij.openapi.editor.Editor)10 TextRange (com.intellij.openapi.util.TextRange)8 XmlAttribute (com.intellij.psi.xml.XmlAttribute)8 File (java.io.File)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)7