From 9b94de60735463dd9464cc2cfcc73b9895f6f2ee Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 24 Jul 2014 16:57:15 +0400 Subject: [PATCH] added assertion on attempt to remove ContentEntry obtained from another instance of ModuleRootModel --- .../openapi/roots/impl/DirectoryIndexTest.java | 2 +- .../openapi/fileEditor/NonProjectFileAccessTest.java | 2 +- .../intellij/openapi/roots/impl/RootModelImpl.java | 11 +++++++++++ .../src/com/intellij/testFramework/PsiTestUtil.java | 4 ++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java b/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java index acc96c8084e6..36140ab44c21 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java @@ -753,7 +753,7 @@ public class DirectoryIndexTest extends IdeaTestCase { assertIteratedContent(fileIndex, Arrays.asList(fileRoot, fileSourceRoot, fileTestSourceRoot), null); // removing file content root - PsiTestUtil.removeContentEntry(myModule, contentEntry); + PsiTestUtil.removeContentEntry(myModule, contentEntry.getFile()); assertNotInProject(fileRoot); assertFalse(fileIndex.isInContent(fileRoot)); assertFalse(fileIndex.isInSource(fileRoot)); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/NonProjectFileAccessTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/NonProjectFileAccessTest.java index e517799165e2..06594d2352bf 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/NonProjectFileAccessTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/NonProjectFileAccessTest.java @@ -245,7 +245,7 @@ public class NonProjectFileAccessTest extends HeavyFileEditorManagerTestCase { assertNotNull(NonProjectFileWritingAccessProvider.getAccessStatus(getProject(), nonProjectFile1)); assertNull(NonProjectFileWritingAccessProvider.getAccessStatus(getProject(), nonProjectFile2)); - PsiTestUtil.removeContentEntry(myModule, contextRoot); + PsiTestUtil.removeContentEntry(myModule, contextRoot.getFile()); // do not add notification panel until access is requested assertNotNull(NonProjectFileWritingAccessProvider.getAccessStatus(getProject(), nonProjectFile1)); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java index 8ece843b5972..540bfe290645 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java @@ -213,6 +213,8 @@ public class RootModelImpl extends RootModelBase implements ModifiableRootModel LOG.assertTrue(myContent.contains(entry)); if (entry instanceof RootModelComponentBase) { Disposer.dispose((RootModelComponentBase)entry); + RootModelImpl entryModel = ((RootModelComponentBase)entry).getRootModel(); + LOG.assertTrue(entryModel == this, "Removing from " + this + " content entry obtained from " + entryModel); } myContent.remove(entry); } @@ -731,6 +733,15 @@ public class RootModelImpl extends RootModelBase implements ModifiableRootModel return myModuleRootManager.getRootModel(); } + @Override + public String toString() { + return "RootModelImpl{" + + "module=" + getModule().getName() + + ", writable=" + myWritable + + ", disposed=" + myDisposed + + '}'; + } + @Nullable @Override public T getModuleExtension(@NotNull final Class klass) { diff --git a/platform/testFramework/src/com/intellij/testFramework/PsiTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PsiTestUtil.java index 0f746d43c6ca..3960159e5bb4 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PsiTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PsiTestUtil.java @@ -220,11 +220,11 @@ public class PsiTestUtil { return entry; } - public static void removeContentEntry(Module module, final ContentEntry e) { + public static void removeContentEntry(Module module, final VirtualFile contentRoot) { ModuleRootModificationUtil.updateModel(module, new Consumer() { @Override public void consume(ModifiableRootModel model) { - model.removeContentEntry(e); + model.removeContentEntry(findContentEntryWithAssertion(model, contentRoot)); } }); }