more logging

This commit is contained in:
Alexey Kudravtsev
2011-05-18 20:17:30 +04:00
parent 8b0517e288
commit 2a9a48bb78
2 changed files with 18 additions and 8 deletions
@@ -40,6 +40,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.EventDispatcher;
import com.intellij.util.SmartList;
import com.intellij.util.text.CharArrayCharSequence;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -84,19 +85,25 @@ public class EditorFactoryImpl extends EditorFactory {
public void validateEditorsAreReleased(Project project) {
for (Editor editor : myEditors) {
if (editor.getProject() == project || editor.getProject() == null) {
fireEditorNotReleasedError(editor);
try {
LOG.error(notReleasedError(editor));
}
finally {
releaseEditor(editor);
}
}
}
}
private static void fireEditorNotReleasedError(final Editor editor) {
@NonNls
public static String notReleasedError(@NotNull Editor editor) {
final String creator = editor.getUserData(EDITOR_CREATOR);
if (creator == null) {
LOG.error("Editor for the document with class:" + editor.getClass().getName() +
" and the following text hasn't been released:\n" + editor.getDocument().getText());
return "Editor of " + editor.getClass() +
" and the following text hasn't been released:\n" + editor.getDocument().getText();
}
else {
LOG.error("Editor with class:" + editor.getClass().getName() + " hasn't been released:\n" + creator);
return "Editor of " + editor.getClass() + " hasn't been released:\n" + creator;
}
}
@@ -42,6 +42,7 @@ import com.intellij.openapi.command.undo.UndoManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.impl.EditorFactoryImpl;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl;
import com.intellij.openapi.fileTypes.FileType;
@@ -529,10 +530,12 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
public static void checkEditorsReleased() {
final Editor[] allEditors = EditorFactory.getInstance().getAllEditors();
if (allEditors.length > 0) {
for (Editor allEditor : allEditors) {
EditorFactory.getInstance().releaseEditor(allEditor);
String fail = null;
for (Editor editor : allEditors) {
fail = EditorFactoryImpl.notReleasedError(editor);
EditorFactory.getInstance().releaseEditor(editor);
}
fail("Unreleased editors: " + allEditors.length);
fail("Unreleased editors: " + allEditors.length + "\n"+fail);
}
}