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