From e4cfc45f55c8201d4e022aa58a8b7f1a7671a752 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 6 Sep 2012 14:22:57 +0200 Subject: [PATCH] more defined dom assertions (EA-38729) --- .../src/com/intellij/util/xml/DomUtil.java | 14 ++++++++++++-- .../xml/highlighting/DomElementsInspection.java | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/xml/dom-openapi/src/com/intellij/util/xml/DomUtil.java b/xml/dom-openapi/src/com/intellij/util/xml/DomUtil.java index d536836f9387..d62d99752e75 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/DomUtil.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/DomUtil.java @@ -228,7 +228,9 @@ public class DomUtil { if (!attribute.isValid()) { throw new AssertionError("Invalid attr: parent.valid=" + tag.isValid()); } - ContainerUtil.addIfNotNull(domManager.getDomElement(attribute), result); + GenericAttributeValue element = domManager.getDomElement(attribute); + checkHasXml(attribute, element); + ContainerUtil.addIfNotNull(element, result); } } if (tags) { @@ -236,7 +238,9 @@ public class DomUtil { if (!subTag.isValid()) { throw new AssertionError("Invalid subtag: parent.valid=" + tag.isValid()); } - ContainerUtil.addIfNotNull(domManager.getDomElement(subTag), result); + DomElement element = domManager.getDomElement(subTag); + checkHasXml(subTag, element); + ContainerUtil.addIfNotNull(element, result); } } return result; @@ -244,6 +248,12 @@ public class DomUtil { return Collections.emptyList(); } + private static void checkHasXml(XmlElement psi, DomElement dom) { + if (dom != null && dom.getXmlElement() == null) { + throw new AssertionError("No xml for dom " + dom + "; attr=" + psi + ", physical=" + psi.isPhysical()); + } + } + public static List getDefinedChildrenOfType(@NotNull final DomElement parent, final Class type, boolean tags, boolean attributes) { return ContainerUtil.findAll(getDefinedChildren(parent, tags, attributes), type); } diff --git a/xml/dom-openapi/src/com/intellij/util/xml/highlighting/DomElementsInspection.java b/xml/dom-openapi/src/com/intellij/util/xml/highlighting/DomElementsInspection.java index d4692d5acc87..18a8a13a0eff 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/highlighting/DomElementsInspection.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/highlighting/DomElementsInspection.java @@ -80,7 +80,7 @@ public abstract class DomElementsInspection extends XmlSup for (final DomElement child : DomUtil.getDefinedChildren(element, true, true)) { final XmlElement element1 = child.getXmlElement(); if (element1 == null) { - LOG.error("child=" + child + "; parent=" + element); + LOG.error("child=" + child + " of class " + child.getClass() + "; parent=" + element); } if (element1.isPhysical()) { visitor.consume(child);