From da32bed971529de16abd798524c7c15704069bee Mon Sep 17 00:00:00 2001 From: peter Date: Sat, 28 Aug 2010 22:42:23 +0100 Subject: [PATCH] update DomFileIndex when the plugins change that contain DomFileDescription's --- .../com/intellij/util/xml/DomFileIndex.java | 10 ++++-- .../xml/impl/DomApplicationComponent.java | 12 +++++++ .../intellij/util/xml/DomFileDescription.java | 32 ++++--------------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/xml/dom-impl/src/com/intellij/util/xml/DomFileIndex.java b/xml/dom-impl/src/com/intellij/util/xml/DomFileIndex.java index 8bfbb341970b..d5b01c6a4835 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/DomFileIndex.java +++ b/xml/dom-impl/src/com/intellij/util/xml/DomFileIndex.java @@ -98,9 +98,13 @@ public class DomFileIndex extends ScalarIndexExtension{ } public int getVersion() { - return 0; + final DomApplicationComponent component = DomApplicationComponent.getInstance(); + int result = 0; + for (DomFileDescription description : component.getAllFileDescriptions()) { + result += description.getVersion(); + result += description.getRootTagName().hashCode(); // so that a plugin enabling/disabling could trigger the reindexing + } + return result; } - private static class RootTagReachedException extends RuntimeException{ - } } diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/DomApplicationComponent.java b/xml/dom-impl/src/com/intellij/util/xml/impl/DomApplicationComponent.java index fe624c3b66ee..0c9ed2900335 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/DomApplicationComponent.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/DomApplicationComponent.java @@ -31,9 +31,12 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.reflect.Type; +import java.util.List; import java.util.Map; import java.util.Set; +import static com.intellij.util.containers.CollectionFactory.arrayList; + /** * @author peter */ @@ -110,6 +113,15 @@ public class DomApplicationComponent { myTypeChooserManager.copyFrom(description.getTypeChooserManager()); } + public synchronized List getAllFileDescriptions() { + final List result = arrayList(); + for (Set descriptions : myRootTagName2FileDescription.values()) { + result.addAll(descriptions); + } + result.addAll(myAcceptingOtherRootTagNamesDescriptions); + return result; + } + @Nullable private synchronized DomFileDescription findFileDescription(Class rootElementClass) { for (Set descriptions : myRootTagName2FileDescription.values()) { diff --git a/xml/dom-openapi/src/com/intellij/util/xml/DomFileDescription.java b/xml/dom-openapi/src/com/intellij/util/xml/DomFileDescription.java index 95ebdcb3c8c1..474e2d7b0a3e 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/DomFileDescription.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/DomFileDescription.java @@ -15,7 +15,6 @@ */ package com.intellij.util.xml; -import com.intellij.openapi.Disposable; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.module.Module; @@ -24,7 +23,6 @@ import com.intellij.util.NotNullFunction; import com.intellij.util.containers.ConcurrentHashMap; import com.intellij.util.containers.ConcurrentInstanceMap; import com.intellij.util.xml.highlighting.DomElementsAnnotator; -import gnu.trove.THashSet; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -116,9 +114,13 @@ public class DomFileDescription { return Collections.emptyList(); } - @Deprecated - protected final void registerClassChooser(final Type aClass, final TypeChooser typeChooser, Disposable parentDisposable) { - registerTypeChooser(aClass, typeChooser); + /** + * @return some version. Override and change (e.g. super.getVersion()+1) when after some changes some files stopped being + * described by this description or vice versa, so that the + * {@link com.intellij.util.xml.DomService#getDomFileCandidates(Class, com.intellij.openapi.project.Project)} index is rebuilt correctly. + */ + public int getVersion() { + return myRootTagName.hashCode(); } protected final void registerTypeChooser(final Type aClass, final TypeChooser typeChooser) { @@ -221,26 +223,6 @@ public class DomFileDescription { return Collections.emptySet(); } - /** - * @deprecated not used - */ - @NotNull - public Set> getDomModelDependencyItems() { - return Collections.emptySet(); - } - - /** - * @deprecated not used - */ - @NotNull - public Set getDomModelDependentFiles(@NotNull DomFileElement changedRoot) { - return Collections.emptySet(); - } - - protected static Set> convertToSet(Class classes) { - return new THashSet>(Arrays.asList(classes)); - } - /** * @param reference DOM reference * @return element, whose all children will be searched for declaration