IDEA-56656 IDEA does not highlight not well-formed XML: comment before XML declaration

This commit is contained in:
Maxim.Mossienko
2010-07-22 19:18:28 +04:00
parent f8dfd6beb4
commit 061b258d8b
4 changed files with 30 additions and 1 deletions
@@ -74,3 +74,4 @@ xml.parsing.closing.tag.name.missing=Closing tag name missing
xml.parsing.closing.tag.is.not.done=Closing tag is not done
attribute.should.be.preceded.with.space=There should be a space between attribute and previous attribute
cdata.end.should.not.appear.in.content.unless.to.mark.end.of.cdata.section=Character sequence ']]>' must not appear in content unless used to mark the end of a CDATA section
xml.declaration.should.precede.all.document.content=Xml declaration should precede all document content
@@ -167,6 +167,30 @@ public class XmlHighlightVisitor extends XmlElementVisitor implements HighlightV
bindMessageToAstNode(childByRole, warning, 0, messageLength, localizedMessage, quickFixActions);
}
@Override
public void visitXmlProcessingInstruction(XmlProcessingInstruction processingInstruction) {
super .visitXmlProcessingInstruction(processingInstruction);
PsiElement parent = processingInstruction.getParent();
if (parent instanceof XmlProlog && processingInstruction.getText().startsWith("<?xml")) {
for(PsiElement e = PsiTreeUtil.prevLeaf(processingInstruction); e != null; e = PsiTreeUtil.prevLeaf(e)) {
if (e instanceof PsiWhiteSpace && PsiTreeUtil.prevLeaf(e) != null ||
e instanceof OuterLanguageElement) {
continue;
}
PsiElement eParent = e.getParent();
if (eParent instanceof PsiComment) e = eParent;
addToResults(HighlightInfo.createHighlightInfo(
HighlightInfoType.ERROR,
e,
XmlErrorMessages.message("xml.declaration.should.precede.all.document.content")
));
}
}
}
private void bindMessageToAstNode(final PsiElement childByRole,
final HighlightInfoType warning,
final int offset,
@@ -40,7 +40,7 @@ public class XmlProcessingInstructionImpl extends XmlElementImpl implements XmlP
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof XmlElementVisitor) {
((XmlElementVisitor)visitor).visitXmlElement(this);
((XmlElementVisitor)visitor).visitXmlProcessingInstruction(this);
}
else {
visitor.visitElement(this);
@@ -65,4 +65,8 @@ public abstract class XmlElementVisitor extends PsiElementVisitor {
public void visitXmlDoctype(XmlDoctype xmlDoctype) {
visitXmlElement(xmlDoctype);
}
public void visitXmlProcessingInstruction(XmlProcessingInstruction processingInstruction) {
visitXmlElement(processingInstruction);
}
}