From 87568772f469b6fd77f21b66549dd68a4e3689fe Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 7 Feb 2011 14:17:56 +0100 Subject: [PATCH] detailed diagnostics why a dom element is invalid --- .../CollectionElementInvocationHandler.java | 13 ++++- .../util/xml/impl/DomFileElementImpl.java | 14 ++++- .../intellij/util/xml/impl/DomImplUtil.java | 19 ++++++ .../util/xml/impl/DomInvocationHandler.java | 58 ++++++++++++------- .../util/xml/impl/DomParentStrategy.java | 3 +- .../xml/impl/DomRootInvocationHandler.java | 13 +++-- .../xml/impl/FixedChildDescriptionImpl.java | 2 +- .../GetCompositeCollectionInvocation.java | 2 +- .../xml/impl/GetFixedChildInvocation.java | 2 +- .../intellij/util/xml/impl/GetInvocation.java | 3 +- .../xml/impl/PhysicalDomParentStrategy.java | 4 +- .../util/xml/impl/RootDomParentStrategy.java | 5 +- .../intellij/util/xml/impl/SetInvocation.java | 2 +- .../xml/impl/VirtualDomParentStrategy.java | 8 ++- 14 files changed, 107 insertions(+), 41 deletions(-) diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/CollectionElementInvocationHandler.java b/xml/dom-impl/src/com/intellij/util/xml/impl/CollectionElementInvocationHandler.java index 13dbcb3d300e..98d9712ea422 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/CollectionElementInvocationHandler.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/CollectionElementInvocationHandler.java @@ -36,8 +36,17 @@ public class CollectionElementInvocationHandler extends DomInvocationHandler implements DomFileElement< } public final boolean isValid() { - return myFile.isValid() && equals(myManager.getFileElement(myFile)); + return checkValidity() == null; + } + + @Nullable + public String checkValidity() { + if (!myFile.isValid()) { + return "Invalid file"; + } + final DomFileElementImpl fileElement = myManager.getFileElement(myFile); + if (!equals(fileElement)) { + return "file element changed: " + fileElement; + } + return null; } @NotNull diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/DomImplUtil.java b/xml/dom-impl/src/com/intellij/util/xml/impl/DomImplUtil.java index 923a1f26e8c6..d661a720598c 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/DomImplUtil.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/DomImplUtil.java @@ -47,6 +47,25 @@ public class DomImplUtil { private DomImplUtil() { } + public static void assertValidity(DomElement element, String msg) { + if (element instanceof DomFileElementImpl) { + final String s = ((DomFileElementImpl)element).checkValidity(); + if (s != null) { + throw new AssertionError(s); + } + return; + } + + final DomInvocationHandler handler = DomManagerImpl.getDomInvocationHandler(element); + assert handler != null; + try { + handler.assertValid(); + } + catch (AssertionError e) { + throw new AssertionError(msg + e.getMessage()); + } + } + public static boolean isTagValueGetter(final JavaMethod method) { if (!isGetter(method)) { return false; diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/DomInvocationHandler.java b/xml/dom-impl/src/com/intellij/util/xml/impl/DomInvocationHandler.java index 27f90f69d9eb..860cd7d90748 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/DomInvocationHandler.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/DomInvocationHandler.java @@ -135,15 +135,16 @@ public abstract class DomInvocationHandler subTags = tagsGetter.fun(this); if (subTags.isEmpty()) return Collections.emptyList(); diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/DomParentStrategy.java b/xml/dom-impl/src/com/intellij/util/xml/impl/DomParentStrategy.java index dbec29a6db8e..7fb7463c711f 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/DomParentStrategy.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/DomParentStrategy.java @@ -34,5 +34,6 @@ public interface DomParentStrategy { @NotNull DomParentStrategy clearXmlElement(); - boolean isValid(); + @Nullable + String checkValidity(); } diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/DomRootInvocationHandler.java b/xml/dom-impl/src/com/intellij/util/xml/impl/DomRootInvocationHandler.java index 16b62e2d7f4a..9b57cfa8147f 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/DomRootInvocationHandler.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/DomRootInvocationHandler.java @@ -76,18 +76,23 @@ public class DomRootInvocationHandler extends DomInvocationHandler result = new SmartList(); final DomInvocationHandler handler = DomManagerImpl.getDomInvocationHandler(element); if (handler != null) { - handler.checkIsValid(); + handler.assertValid(); for (int i = 0; i < myCount; i++) { result.add(handler.getFixedChild(Pair.create(this, i)).getProxy()); } diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/GetCompositeCollectionInvocation.java b/xml/dom-impl/src/com/intellij/util/xml/impl/GetCompositeCollectionInvocation.java index 9e2c6ca67a6d..b4457905f8c6 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/GetCompositeCollectionInvocation.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/GetCompositeCollectionInvocation.java @@ -33,7 +33,7 @@ class GetCompositeCollectionInvocation implements Invocation { } public Object invoke(final DomInvocationHandler handler, final Object[] args) throws Throwable { - handler.checkIsValid(); + handler.assertValid(); Map map = new THashMap(); for (final CollectionChildDescriptionImpl qname : myQnames) { for (DomElement element : handler.getCollectionChildren(qname, qname.getTagsGetter())) { diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/GetFixedChildInvocation.java b/xml/dom-impl/src/com/intellij/util/xml/impl/GetFixedChildInvocation.java index d3e1ad7f6b1a..82cce2c18577 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/GetFixedChildInvocation.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/GetFixedChildInvocation.java @@ -16,7 +16,7 @@ public class GetFixedChildInvocation implements Invocation { } public Object invoke(final DomInvocationHandler handler, final Object[] args) throws Throwable { - handler.checkIsValid(); + handler.assertValid(); return handler.getFixedChild(myPair).getProxy(); } } diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/GetInvocation.java b/xml/dom-impl/src/com/intellij/util/xml/impl/GetInvocation.java index 4d82880a67ce..7f58cef4c1f5 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/GetInvocation.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/GetInvocation.java @@ -7,7 +7,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; -import com.intellij.psi.PsiManager; import com.intellij.psi.util.CachedValue; import com.intellij.psi.util.CachedValueProvider; import com.intellij.psi.util.CachedValuesManager; @@ -34,7 +33,7 @@ public class GetInvocation implements Invocation { } public Object invoke(final DomInvocationHandler handler, final Object[] args) throws Throwable { - handler.checkIsValid(); + handler.assertValid(); if (myConverter == Converter.EMPTY_CONVERTER) { return getValueInner(handler, myConverter); } diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java b/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java index 31951e84cf80..db329be62594 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/PhysicalDomParentStrategy.java @@ -73,8 +73,8 @@ public class PhysicalDomParentStrategy implements DomParentStrategy { return new VirtualDomParentStrategy(parent); } - public boolean isValid() { - return myElement.isValid(); + public String checkValidity() { + return myElement.isValid() ? null : "Invalid PSI"; } public boolean equals(final Object o) { diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/RootDomParentStrategy.java b/xml/dom-impl/src/com/intellij/util/xml/impl/RootDomParentStrategy.java index cfd80b50499d..4e9daa90c496 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/RootDomParentStrategy.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/RootDomParentStrategy.java @@ -53,8 +53,9 @@ public class RootDomParentStrategy implements DomParentStrategy { return this; } - public boolean isValid() { - return myFileElement.isValid(); + @Override + public String checkValidity() { + return myFileElement.checkValidity(); } public boolean equals(final Object o) { diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/SetInvocation.java b/xml/dom-impl/src/com/intellij/util/xml/impl/SetInvocation.java index 78ff5ba07919..487df9a31fb4 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/SetInvocation.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/SetInvocation.java @@ -17,7 +17,7 @@ public class SetInvocation implements Invocation { } public Object invoke(final DomInvocationHandler handler, final Object[] args) throws Throwable { - handler.checkIsValid(); + handler.assertValid(); final SubTag annotation = handler.getAnnotation(SubTag.class); final Object arg = args[0]; if (annotation != null && annotation.indicator() && arg instanceof Boolean) { diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/VirtualDomParentStrategy.java b/xml/dom-impl/src/com/intellij/util/xml/impl/VirtualDomParentStrategy.java index a2dc0d6f8257..ad7a3f9b2436 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/VirtualDomParentStrategy.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/VirtualDomParentStrategy.java @@ -72,8 +72,12 @@ public class VirtualDomParentStrategy implements DomParentStrategy { return this; } - public synchronized boolean isValid() { - return getModCount() == myModCount; + @Override + public synchronized String checkValidity() { + if (getModCount() == myModCount) { + return null; + } + return "mod count changed"; } public boolean equals(final Object o) {