added assertion on attempt to remove ContentEntry obtained from another instance of ModuleRootModel

This commit is contained in:
nik
2014-07-25 10:05:19 +04:00
parent 802db2cf3d
commit 9b94de6073
4 changed files with 15 additions and 4 deletions
@@ -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));
@@ -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));
@@ -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> T getModuleExtension(@NotNull final Class<T> klass) {
@@ -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<ModifiableRootModel>() {
@Override
public void consume(ModifiableRootModel model) {
model.removeContentEntry(e);
model.removeContentEntry(findContentEntryWithAssertion(model, contentRoot));
}
});
}