From 05a1f2b453cc3a2f5f61dbe81ad6c969f3a00927 Mon Sep 17 00:00:00 2001 From: Peter Gromov Date: Thu, 3 Jul 2008 00:02:54 +0400 Subject: [PATCH] dom elements won't survive on tag name change ability to extend dom with custom children --- .../impl/CollectionElementInvocationHandler.java | 7 +++++++ .../xml/impl/CustomDomChildrenDescriptionImpl.java | 14 ++++++++++--- .../util/xml/impl/DomInvocationHandler.java | 8 ++++---- .../com/intellij/util/xml/impl/DomManagerImpl.java | 7 ++----- .../intellij/util/xml/impl/DynamicGenericInfo.java | 16 ++++++--------- .../xml/impl/IndexedElementInvocationHandler.java | 24 +++++++++++++++++++--- .../intellij/util/xml/impl/StaticGenericInfo.java | 2 +- .../intellij/util/xml/reflect/DomExtenderEP.java | 2 +- .../xml/reflect/DomExtensionsRegistrarImpl.java | 11 ++++++++++ .../com/intellij/util/xml/reflect/DomExtender.java | 3 +-- .../intellij/util/xml/reflect/DomExtension.java | 2 -- .../util/xml/reflect/DomExtensionsRegistrar.java | 7 +++++++ 12 files changed, 72 insertions(+), 31 deletions(-) diff --git a/dom/impl/src/com/intellij/util/xml/impl/CollectionElementInvocationHandler.java b/dom/impl/src/com/intellij/util/xml/impl/CollectionElementInvocationHandler.java index f307924d26..eb89a34fad 100644 --- a/dom/impl/src/com/intellij/util/xml/impl/CollectionElementInvocationHandler.java +++ b/dom/impl/src/com/intellij/util/xml/impl/CollectionElementInvocationHandler.java @@ -17,6 +17,7 @@ import java.util.List; * @author peter */ public class CollectionElementInvocationHandler extends DomInvocationHandler{ + private final String myTagQName; public CollectionElementInvocationHandler(final Type type, @NotNull final XmlTag tag, final AbstractCollectionChildDescription description, @@ -31,6 +32,7 @@ public class CollectionElementInvocationHandler extends DomInvocationHandler myCachedValue; private final Project myProject; private final ThreadLocal myComputing = new ThreadLocal(); private ChildrenDescriptionsHolder myAttributes; private ChildrenDescriptionsHolder myFixeds; private ChildrenDescriptionsHolder myCollections; + private CustomDomChildrenDescriptionImpl myCustomChildren; private static final JBReentrantReadWriteLock rwl = LockFactory.createReadWriteLock(); private static final JBLock r = rwl.readLock(); private static final JBLock w = rwl.writeLock(); @@ -48,7 +46,6 @@ public class DynamicGenericInfo extends DomGenericInfoEx { myInvocationHandler = handler; myStaticGenericInfo = staticGenericInfo; myProject = project; - myCachedValue = PsiManager.getInstance(myProject).getCachedValuesManager().createCachedValue(new MyCachedValueProvider(), false); myAttributes = staticGenericInfo.getAttributes(); myFixeds = staticGenericInfo.getFixed(); @@ -70,15 +67,12 @@ public class DynamicGenericInfo extends DomGenericInfoEx { private void _checkInitialized() { myStaticGenericInfo.buildMethodMaps(); - if (myCachedValue.hasUpToDateValue()) return; if (myComputing.get() != null) return; r.unlock(); boolean rlocked = false; try { w.lock(); try { - if (myCachedValue.hasUpToDateValue()) return; - myAttributes = myStaticGenericInfo.getAttributes(); myFixeds = myStaticGenericInfo.getFixed(); myCollections = myStaticGenericInfo.getCollections(); @@ -107,7 +101,6 @@ public class DynamicGenericInfo extends DomGenericInfoEx { w.lock(); try { - if (myCachedValue.hasUpToDateValue()) return; if (registrar != null) { final List attributes = registrar.getAttributes(); if (!attributes.isEmpty()) { @@ -130,9 +123,11 @@ public class DynamicGenericInfo extends DomGenericInfoEx { myCollections.addDescription(extension.addAnnotations(new CollectionChildDescriptionImpl(extension.getXmlName(), extension.getType(), Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST))); } } + final DomExtensionImpl extension = registrar.getCustomChildrenType(); + if (extension != null) { + myCustomChildren = new CustomDomChildrenDescriptionImpl(null, extension.getType()); + } } - ((MyCachedValueProvider)myCachedValue.getValueProvider()).deps = registrar == null ? ArrayUtil.EMPTY_OBJECT_ARRAY : registrar.getDependencies(); - myCachedValue.getValue(); } finally { myComputing.set(null); @@ -159,6 +154,7 @@ public class DynamicGenericInfo extends DomGenericInfoEx { @Nullable public CustomDomChildrenDescriptionImpl getCustomNameChildrenDescription() { + if (myCustomChildren != null) return myCustomChildren; return myStaticGenericInfo.getCustomNameChildrenDescription(); } diff --git a/dom/impl/src/com/intellij/util/xml/impl/IndexedElementInvocationHandler.java b/dom/impl/src/com/intellij/util/xml/impl/IndexedElementInvocationHandler.java index e79482d11c..7a253774ea 100644 --- a/dom/impl/src/com/intellij/util/xml/impl/IndexedElementInvocationHandler.java +++ b/dom/impl/src/com/intellij/util/xml/impl/IndexedElementInvocationHandler.java @@ -22,14 +22,27 @@ import java.util.List; public class IndexedElementInvocationHandler extends DomInvocationHandler{ private static final Logger LOG = Logger.getInstance("#com.intellij.util.xml.impl.IndexedElementInvocationHandler"); private final int myIndex; + private String myNamespace; public IndexedElementInvocationHandler(final EvaluatedXmlName tagName, final FixedChildDescriptionImpl description, final int index, final DomParentStrategy strategy, - final DomManagerImpl manager) { + final DomManagerImpl manager, + final String namespace) { super(description.getType(), strategy, tagName, description, manager, strategy.getXmlElement() != null); myIndex = index; + myNamespace = namespace; + } + + @Override + public boolean isValid() { + final XmlTag tag = getXmlTag(); + if (!super.isValid()) return false; + if (tag == null) return true; + final String localName = getXmlElementName(); + if (localName.indexOf(':') > 0 && localName.equals(tag.getName())) return true; + return localName.equals(tag.getLocalName()) && myNamespace.equals(tag.getNamespace()); } @SuppressWarnings({"EqualsWhichDoesntCheckParameterClass"}) @@ -48,7 +61,9 @@ public class IndexedElementInvocationHandler extends DomInvocationHandler tags = DomImplUtil.findSubTags(tag, getXmlName(), parentHandler.getFile()); if (tags.size() <= myIndex) return null; - return tags.get(myIndex); + final XmlTag childTag = tags.get(myIndex); + myNamespace = childTag.getNamespace(); + return childTag; } protected XmlTag setEmptyXmlTag() { @@ -58,7 +73,9 @@ public class IndexedElementInvocationHandler extends DomInvocationHandler tags = DomImplUtil.findSubTags(parent.getXmlTag(), getXmlName(), xmlFile); if (tags.size() > myIndex) { - return tags.get(myIndex); + final XmlTag tag = tags.get(myIndex); + myNamespace = tag.getNamespace(); + return tag; } final XmlTag[] newTag = new XmlTag[1]; @@ -73,6 +90,7 @@ public class IndexedElementInvocationHandler extends DomInvocationHandler handler, final Object[] args) throws Throwable { diff --git a/dom/impl/src/com/intellij/util/xml/reflect/DomExtenderEP.java b/dom/impl/src/com/intellij/util/xml/reflect/DomExtenderEP.java index a9493e1c7e..37b50fcbce 100644 --- a/dom/impl/src/com/intellij/util/xml/reflect/DomExtenderEP.java +++ b/dom/impl/src/com/intellij/util/xml/reflect/DomExtenderEP.java @@ -44,7 +44,7 @@ public class DomExtenderEP extends AbstractExtensionPointBean { if (registrar == null) { registrar = new DomExtensionsRegistrarImpl(); } - registrar.addDependencies(myExtender.registerExtensions(element, registrar)); + myExtender.registerExtensions(element, registrar); } return registrar; } diff --git a/dom/impl/src/com/intellij/util/xml/reflect/DomExtensionsRegistrarImpl.java b/dom/impl/src/com/intellij/util/xml/reflect/DomExtensionsRegistrarImpl.java index abeec032a8..536c46c4e9 100644 --- a/dom/impl/src/com/intellij/util/xml/reflect/DomExtensionsRegistrarImpl.java +++ b/dom/impl/src/com/intellij/util/xml/reflect/DomExtensionsRegistrarImpl.java @@ -24,6 +24,7 @@ public class DomExtensionsRegistrarImpl implements DomExtensionsRegistrar { private final List myFixeds = new SmartList(); private final List myCollections = new SmartList(); private final Set myDependencies = new THashSet(); + private DomExtensionImpl myCustomChildrenType; public List getAttributes() { return myAttributes; @@ -36,6 +37,10 @@ public class DomExtensionsRegistrarImpl implements DomExtensionsRegistrar { return myCollections; } + public DomExtensionImpl getCustomChildrenType() { + return myCustomChildrenType; + } + @NotNull public final DomExtension registerFixedNumberChildrenExtension(@NotNull final XmlName name, @NotNull final Type type, final int count) { assert count > 0; @@ -63,6 +68,12 @@ public class DomExtensionsRegistrarImpl implements DomExtensionsRegistrar { return addExtension(myAttributes, name, type); } + @NotNull + public DomExtension registerCustomChildrenExtension(@NotNull final Type type) { + assert myCustomChildrenType == null; + return myCustomChildrenType = new DomExtensionImpl(type, null); + } + private static DomExtensionImpl addExtension(final List list, final XmlName name, final Type type) { final DomExtensionImpl extension = new DomExtensionImpl(type, name); list.add(extension); diff --git a/dom/openapi/src/com/intellij/util/xml/reflect/DomExtender.java b/dom/openapi/src/com/intellij/util/xml/reflect/DomExtender.java index 3022495ad8..6ef69e5761 100644 --- a/dom/openapi/src/com/intellij/util/xml/reflect/DomExtender.java +++ b/dom/openapi/src/com/intellij/util/xml/reflect/DomExtender.java @@ -31,7 +31,6 @@ public abstract class DomExtender { /** * @param t DOM element where new children may be added to * @param registrar a place to register your own DOM children descriptions - * @return dependency items, whose change should trigger dynamic DOM rebuild for this element */ - public abstract Object[] registerExtensions(@NotNull T t, @NotNull final DomExtensionsRegistrar registrar); + public abstract void registerExtensions(@NotNull T t, @NotNull final DomExtensionsRegistrar registrar); } diff --git a/dom/openapi/src/com/intellij/util/xml/reflect/DomExtension.java b/dom/openapi/src/com/intellij/util/xml/reflect/DomExtension.java index 037a47c18f..e3ed55ae30 100644 --- a/dom/openapi/src/com/intellij/util/xml/reflect/DomExtension.java +++ b/dom/openapi/src/com/intellij/util/xml/reflect/DomExtension.java @@ -30,8 +30,6 @@ import java.lang.reflect.Type; */ public interface DomExtension { Key KEY_DECLARATION = new Key("DOM_DECLARATION"); - @NotNull - XmlName getXmlName(); @NotNull Type getType(); diff --git a/dom/openapi/src/com/intellij/util/xml/reflect/DomExtensionsRegistrar.java b/dom/openapi/src/com/intellij/util/xml/reflect/DomExtensionsRegistrar.java index 26af2f7aa1..04605e518c 100644 --- a/dom/openapi/src/com/intellij/util/xml/reflect/DomExtensionsRegistrar.java +++ b/dom/openapi/src/com/intellij/util/xml/reflect/DomExtensionsRegistrar.java @@ -39,4 +39,11 @@ public interface DomExtensionsRegistrar { */ @NotNull DomExtension registerAttributeChildExtension(@NotNull XmlName name, @NotNull final Type type); + /** + * @param type + * @return + * @see com.intellij.util.xml.CustomChildren + */ + @NotNull DomExtension registerCustomChildrenExtension(@NotNull final Type type); + } -- 2.11.4.GIT