mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use PSI for building root tag stub (support incomplete root tag like "<foo")
This commit is contained in:
@@ -65,7 +65,7 @@ public class DomServiceImpl extends DomService {
|
||||
};
|
||||
|
||||
@NotNull
|
||||
private static XmlFileHeader calcXmlFileHeader(final PsiFile file) {
|
||||
private static XmlFileHeader calcXmlFileHeader(final XmlFile file) {
|
||||
|
||||
if (!DomStubBuilder.isStubBuilding(file) && file.getFileType() == XmlFileType.INSTANCE) {
|
||||
VirtualFile virtualFile = file.getVirtualFile();
|
||||
@@ -77,38 +77,35 @@ public class DomServiceImpl extends DomService {
|
||||
}
|
||||
}
|
||||
|
||||
if (file instanceof XmlFile && file.getNode().isParsed()) {
|
||||
final XmlDocument document = ((XmlFile)file).getDocument();
|
||||
if (document != null) {
|
||||
String publicId = null;
|
||||
String systemId = null;
|
||||
final XmlProlog prolog = document.getProlog();
|
||||
if (prolog != null) {
|
||||
final XmlDoctype doctype = prolog.getDoctype();
|
||||
if (doctype != null) {
|
||||
publicId = doctype.getPublicId();
|
||||
systemId = doctype.getSystemId();
|
||||
if (systemId == null) {
|
||||
systemId = doctype.getDtdUri();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final XmlTag tag = document.getRootTag();
|
||||
if (tag != null) {
|
||||
String localName = tag.getLocalName();
|
||||
if (StringUtil.isNotEmpty(localName)) {
|
||||
if (tag.getPrevSibling() instanceof PsiErrorElement) {
|
||||
return XmlFileHeader.EMPTY;
|
||||
}
|
||||
|
||||
String psiNs = tag.getNamespace();
|
||||
return new XmlFileHeader(localName, psiNs == XmlUtil.EMPTY_URI || Comparing.equal(psiNs, systemId) ? null : psiNs, publicId,
|
||||
systemId);
|
||||
final XmlDocument document = file.getDocument();
|
||||
if (document != null) {
|
||||
String publicId = null;
|
||||
String systemId = null;
|
||||
final XmlProlog prolog = document.getProlog();
|
||||
if (prolog != null) {
|
||||
final XmlDoctype doctype = prolog.getDoctype();
|
||||
if (doctype != null) {
|
||||
publicId = doctype.getPublicId();
|
||||
systemId = doctype.getSystemId();
|
||||
if (systemId == null) {
|
||||
systemId = doctype.getDtdUri();
|
||||
}
|
||||
}
|
||||
}
|
||||
return XmlFileHeader.EMPTY;
|
||||
|
||||
final XmlTag tag = document.getRootTag();
|
||||
if (tag != null) {
|
||||
String localName = tag.getLocalName();
|
||||
if (StringUtil.isNotEmpty(localName)) {
|
||||
if (tag.getPrevSibling() instanceof PsiErrorElement) {
|
||||
return XmlFileHeader.EMPTY;
|
||||
}
|
||||
|
||||
String psiNs = tag.getNamespace();
|
||||
return new XmlFileHeader(localName, psiNs == XmlUtil.EMPTY_URI || Comparing.equal(psiNs, systemId) ? null : psiNs, publicId,
|
||||
systemId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.isValid()) return XmlFileHeader.EMPTY;
|
||||
|
||||
@@ -29,8 +29,6 @@ import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.util.xml.*;
|
||||
import com.intellij.util.xml.stubs.FileStub;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 8/2/12
|
||||
@@ -62,7 +60,7 @@ public class DomStubBuilder implements BinaryFileStubBuilder {
|
||||
DomFileElement<? extends DomElement> fileElement = manager.getFileElement(xmlFile);
|
||||
if (fileElement == null || !fileElement.getFileDescription().hasStubs()) return null;
|
||||
|
||||
XmlFileHeader header = NanoXmlUtil.parseHeader(new ByteArrayInputStream(content));
|
||||
XmlFileHeader header = DomService.getInstance().getXmlFileHeader(xmlFile);
|
||||
if (header.getRootTagLocalName() == null) {
|
||||
LOG.error("null root tag for " + fileElement + " for " + file);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<!DOCTYPE beans PUBLIC "-//FOO" "http://foo.dtd">
|
||||
|
||||
<foo
|
||||
@@ -49,6 +49,11 @@ public class DomStubBuilderTest extends DomStubTest {
|
||||
" Element:bar\n");
|
||||
}
|
||||
|
||||
public void testNullTag() throws Exception {
|
||||
doBuilderTest("nullTag.xml", "File:foo\n" +
|
||||
" Element:foo\n");
|
||||
}
|
||||
|
||||
public static class TestExtender extends DomExtender<Bar> {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,11 +36,17 @@ import com.intellij.util.xml.stubs.model.Foo;
|
||||
*/
|
||||
public abstract class DomStubTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
private static final DomFileDescription<Foo> DOM_FILE_DESCRIPTION = new DomFileDescription<Foo>(Foo.class, "foo") {
|
||||
private static final String HTTP_FOO_DTD = "http://foo.dtd";
|
||||
private static final DomFileDescription<Foo> DOM_FILE_DESCRIPTION = new DomFileDescription<Foo>(Foo.class, "foo", HTTP_FOO_DTD) {
|
||||
@Override
|
||||
public boolean hasStubs() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeFileDescription() {
|
||||
registerNamespacePolicy("foo", HTTP_FOO_DTD);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user