From 8bb69797931a6697e89820178affc781cb42900d Mon Sep 17 00:00:00 2001 From: Olesya Smirnova Date: Fri, 11 Mar 2005 15:50:45 +0300 Subject: [PATCH] Saving calling stack trace when editor is created --- .../editor/impl/EditorFactoryImpl.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/source/com/intellij/openapi/editor/impl/EditorFactoryImpl.java b/source/com/intellij/openapi/editor/impl/EditorFactoryImpl.java index 2aa468d0c6be..0642c980cc5f 100644 --- a/source/com/intellij/openapi/editor/impl/EditorFactoryImpl.java +++ b/source/com/intellij/openapi/editor/impl/EditorFactoryImpl.java @@ -14,10 +14,13 @@ import com.intellij.openapi.editor.impl.event.EditorEventMulticasterImpl; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ProjectManagerAdapter; +import com.intellij.openapi.util.Key; import com.intellij.util.EventDispatcher; import com.intellij.util.text.CharArrayCharSequence; import javax.swing.*; +import java.io.ByteArrayOutputStream; +import java.io.PrintWriter; import java.util.ArrayList; public class EditorFactoryImpl extends EditorFactory { @@ -28,6 +31,7 @@ public class EditorFactoryImpl extends EditorFactory { private EventDispatcher myEditorFactoryEventDispatcher = EventDispatcher.create(EditorFactoryListener.class); private ArrayList myEditors = new ArrayList(); + private static final Key EDITOR_CREATOR = new Key("Editor creator"); public EditorFactoryImpl(ProjectManager projectManager) { LaterInvocatorEx.addModalityStateListener( @@ -62,7 +66,14 @@ public class EditorFactoryImpl extends EditorFactory { for (int i = 0; i < myEditors.size(); i++) { Editor editor = myEditors.get(i); if (editor.getProject() == project) { - LOG.error("Editor for the document with the following text hasn't been released:\n" + editor.getDocument().getText()); + final Exception creator = editor.getUserData(EDITOR_CREATOR); + if (creator == null) { + LOG.error("Editor for the document with the following text hasn't been released:\n" + editor.getDocument().getText()); + } else { + final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + creator.printStackTrace(new PrintWriter(buffer)); + LOG.error("Editor hasn't been released:\n" + new String(buffer.toByteArray())); + } } } } @@ -115,10 +126,19 @@ public class EditorFactoryImpl extends EditorFactory { //Thread.dumpStack(); } + try { + throw new RuntimeException("Editor created"); + } + catch (RuntimeException e) { + editor.putUserData(EDITOR_CREATOR, e); + } + + return editor; } public void releaseEditor(Editor editor) { + editor.putUserData(EDITOR_CREATOR, null); ((EditorImpl)editor).release(); myEditors.remove(editor); myEditorFactoryEventDispatcher.getMulticaster().editorReleased(new EditorFactoryEvent(this, editor));