avoid NPEs in command-line diff application

This commit is contained in:
Dmitry Batrak
2015-03-31 12:34:22 +03:00
parent 7cb783f35e
commit 6b27187749
2 changed files with 17 additions and 12 deletions
@@ -56,17 +56,19 @@ public class PsiAwareTextEditorProvider extends TextEditorProvider implements As
LOG.error("Cannot open text editor for " + file);
}
CodeFoldingState state = null;
try {
Document document = FileDocumentManager.getInstance().getDocument(file);
if (document != null) {
state = CodeFoldingManager.getInstance(project).buildInitialFoldings(document);
if (!project.isDefault()) { // There's no CodeFoldingManager for default project (which is used in diff command-line application)
try {
Document document = FileDocumentManager.getInstance().getDocument(file);
if (document != null) {
state = CodeFoldingManager.getInstance(project).buildInitialFoldings(document);
}
}
catch (ProcessCanceledException e) {
throw e;
}
catch (Exception e) {
LOG.error("Error building initial foldings", e);
}
}
catch (ProcessCanceledException e) {
throw e;
}
catch (Exception e) {
LOG.error("Error building initial foldings", e);
}
final CodeFoldingState finalState = state;
return new Builder() {
@@ -133,7 +133,9 @@ class TextEditorComponent extends JBLoadingPanel implements DataProvider {
*/
void dispose(){
myDocument.removeDocumentListener(myDocumentListener);
EditorHistoryManager.getInstance(myProject).updateHistoryEntry(myFile, false);
if (!myProject.isDefault()) { // There's no EditorHistoryManager for default project (which is used in diff command-line application)
EditorHistoryManager.getInstance(myProject).updateHistoryEntry(myFile, false);
}
disposeEditor(myEditor);
myConnection.disconnect();
@@ -276,7 +278,8 @@ class TextEditorComponent extends JBLoadingPanel implements DataProvider {
final Editor e = validateCurrentEditor();
if (e == null) return null;
if (!myProject.isDisposed()) {
// There's no FileEditorManager for default project (which is used in diff command-line application)
if (!myProject.isDisposed() && !myProject.isDefault()) {
final Object o = FileEditorManager.getInstance(myProject).getData(dataId, e, e.getCaretModel().getCurrentCaret());
if (o != null) return o;
}