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);
}
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());
}
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();
}
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());
}
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());
}
Aggregations