if (editor == null) return;
final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (psiFile == null) return;
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
public void run() {
final CodeInsightActionHandler handler = getHandler();
final Runnable action = new Runnable() {
public void run() {
if (!ApplicationManager.getApplication().isUnitTestMode() && !editor.getContentComponent().isShowing()) return;
handler.invoke(project, editor, psiFile);
}
};
if (handler.startInWriteAction()) {
ApplicationManager.getApplication().runWriteAction(action);
}
else {
action.run();
}