Skip to content

Commit 7c785f6

Browse files
authored
Merge pull request #26 from rufinio/issue25
Fixed #25. Added some sanity checks
2 parents 41438f3 + 8c3df8b commit 7c785f6

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

plugin/src/org/wangzw/plugin/cppstyle/ClangFormatFormatter.java

+19-9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import org.eclipse.ui.IFileEditorInput;
3939
import org.eclipse.ui.console.MessageConsoleStream;
4040
import org.eclipse.ui.IWorkbenchPage;
41+
import org.eclipse.ui.IWorkbenchWindow;
42+
import org.eclipse.ui.IWorkbench;
4143
import org.eclipse.ui.PlatformUI;
4244
import org.eclipse.ui.IEditorInput;
4345
import org.eclipse.ui.IEditorPart;
@@ -74,15 +76,23 @@ public void setOptions(Map<String, ?> options) {
7476
}
7577

7678
private String getSourceFilePath() {
77-
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
78-
if (page != null) {
79-
IEditorPart activeEditor = page.getActiveEditor();
80-
if (activeEditor != null) {
81-
IEditorInput editorInput = activeEditor.getEditorInput();
82-
if (editorInput != null) {
83-
IPath filePath = getSourceFilePathFromEditorInput(editorInput);
84-
if (filePath != null) {
85-
return filePath.toOSString();
79+
IWorkbench wb = PlatformUI.getWorkbench();
80+
if (wb != null)
81+
{
82+
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
83+
if (window != null)
84+
{
85+
IWorkbenchPage page = window.getActivePage();
86+
if (page != null) {
87+
IEditorPart activeEditor = page.getActiveEditor();
88+
if (activeEditor != null) {
89+
IEditorInput editorInput = activeEditor.getEditorInput();
90+
if (editorInput != null) {
91+
IPath filePath = getSourceFilePathFromEditorInput(editorInput);
92+
if (filePath != null) {
93+
return filePath.toOSString();
94+
}
95+
}
8696
}
8797
}
8898
}

0 commit comments

Comments
 (0)