diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java index 96b46d39eb8e..39f446ac2b6b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/DocumentImpl.java @@ -54,11 +54,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.CopyOnWriteArrayList; public class DocumentImpl extends UserDataHolderBase implements DocumentEx { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.DocumentImpl"); - private final List myDocumentListeners = ContainerUtil.createEmptyCOWList(); + private final CopyOnWriteArrayList myDocumentListeners = ContainerUtil.createEmptyCOWList(); private final RangeMarkerTree myRangeMarkers = new RangeMarkerTree(this); private final List myGuardedBlocks = new ArrayList(); private ReadonlyFragmentModificationHandler myReadonlyFragmentModificationHandler; @@ -547,8 +548,8 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { public void addDocumentListener(@NotNull DocumentListener listener) { myCachedDocumentListeners = null; - LOG.assertTrue(!myDocumentListeners.contains(listener), listener); - myDocumentListeners.add(listener); + boolean added = myDocumentListeners.addIfAbsent(listener); + LOG.assertTrue(added, listener); } public void addDocumentListener(@NotNull final DocumentListener listener, @NotNull Disposable parentDisposable) { @@ -609,14 +610,16 @@ public class DocumentImpl extends UserDataHolderBase implements DocumentEx { return lineCount; } + @NotNull private DocumentListener[] getCachedListeners() { - if (myCachedDocumentListeners == null) { + DocumentListener[] cachedListeners = myCachedDocumentListeners; + if (cachedListeners == null) { DocumentListener[] listeners = myDocumentListeners.toArray(new DocumentListener[myDocumentListeners.size()]); Arrays.sort(listeners, PrioritizedDocumentListener.COMPARATOR); - myCachedDocumentListeners = listeners; + myCachedDocumentListeners = cachedListeners = listeners; } - return myCachedDocumentListeners; + return cachedListeners; } public void fireReadOnlyModificationAttempt() { diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 7ac2cc1acdc6..948a00cf3765 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -503,7 +503,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @Override public void launchAction(@NotNull final IntentionAction action) { - new WriteCommandAction(myProjectFixture.getProject()) { + new WriteCommandAction(getProject()) { @Override protected void run(final Result result) throws Exception { ShowIntentionActionsHandler.chooseActionAndInvoke(getFile(), getEditor(), action, action.getText()); @@ -604,12 +604,12 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig final String newName, final boolean searchInComments, final boolean searchTextOccurrences) { - new WriteCommandAction.Simple(myProjectFixture.getProject()) { + new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Exception { final PsiElement substitution = RenamePsiElementProcessor.forElement(element).substituteElementToRename(element, myEditor); if (substitution == null) return; - new RenameProcessor(myProjectFixture.getProject(), substitution, newName, searchInComments, searchTextOccurrences).run(); + new RenameProcessor(getProject(), substitution, newName, searchInComments, searchTextOccurrences).run(); } }.execute().throwException(); } @@ -739,7 +739,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @Override public void moveFile(@NonNls final String filePath, @NonNls final String to, final String... additionalFiles) { assertInitialized(); - final Project project = myProjectFixture.getProject(); + final Project project = getProject(); new WriteCommandAction.Simple(project) { @Override protected void run() throws Exception { @@ -779,7 +779,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @NotNull public Collection findAllGutters(final String filePath) { assertInitialized(); - final Project project = myProjectFixture.getProject(); + final Project project = getProject(); final SortedMap> result = new TreeMap>(); configureByFilesInner(filePath); @@ -944,7 +944,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @Override public void checkResultByFile(final String expectedFile, final boolean ignoreTrailingWhitespaces) { assertInitialized(); - new WriteCommandAction.Simple(myProjectFixture.getProject()) { + new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Exception { @@ -957,7 +957,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig public void checkResultByFile(final String filePath, final String expectedFile, final boolean ignoreTrailingWhitespaces) { assertInitialized(); - new WriteCommandAction.Simple(myProjectFixture.getProject()) { + new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Exception { @@ -1333,7 +1333,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @Override @NotNull public List doHighlighting() { - final Project project = myProjectFixture.getProject(); + final Project project = getProject(); new WriteCommandAction.Simple(project) { @Override protected void run() throws Throwable { @@ -1538,7 +1538,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig final SelectionAndCaretMarkupLoader loader, String actualText) { assertInitialized(); - Project project = myProjectFixture.getProject(); + Project project = getProject(); project.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting(); if (stripTrailingSpaces) { diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java index 0a13e332fd28..15c3411bbb24 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightIdeaTestFixtureImpl.java @@ -53,6 +53,16 @@ class LightIdeaTestFixtureImpl extends BaseFixture implements LightIdeaTestFixtu storeSettings(); } + @Override + public void tearDown() throws Exception { + CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings(); + checkForSettingsDamage(); + LightPlatformTestCase.doTearDown(getProject(), LightPlatformTestCase.getApplication(), true); + super.tearDown(); + ((InjectedLanguageManagerImpl)InjectedLanguageManager.getInstance(getProject())).checkInjectorsAreDisposed(); + } + + private class MyDataProvider implements DataProvider { @Override @Nullable @@ -69,16 +79,6 @@ class LightIdeaTestFixtureImpl extends BaseFixture implements LightIdeaTestFixtu } } - - @Override - public void tearDown() throws Exception { - CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings(); - checkForSettingsDamage(); - LightPlatformTestCase.doTearDown(getProject(), LightPlatformTestCase.getApplication(), true); - super.tearDown(); - ((InjectedLanguageManagerImpl)InjectedLanguageManager.getInstance(getProject())).checkInjectorsAreDisposed(); - } - @Override public Project getProject() { return LightPlatformTestCase.getProject();