Skip to content

Commit

Permalink
Fixed wangzw#25. Add some sanity checks to avoid NullPointerException…
Browse files Browse the repository at this point in the history
… by adding new class
  • Loading branch information
rufinio committed Oct 19, 2017
1 parent 41438f3 commit 8c3df8b
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions plugin/src/org/wangzw/plugin/cppstyle/ClangFormatFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.console.MessageConsoleStream;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
Expand Down Expand Up @@ -74,15 +76,23 @@ public void setOptions(Map<String, ?> options) {
}

private String getSourceFilePath() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (page != null) {
IEditorPart activeEditor = page.getActiveEditor();
if (activeEditor != null) {
IEditorInput editorInput = activeEditor.getEditorInput();
if (editorInput != null) {
IPath filePath = getSourceFilePathFromEditorInput(editorInput);
if (filePath != null) {
return filePath.toOSString();
IWorkbench wb = PlatformUI.getWorkbench();
if (wb != null)
{
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
if (window != null)
{
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IEditorPart activeEditor = page.getActiveEditor();
if (activeEditor != null) {
IEditorInput editorInput = activeEditor.getEditorInput();
if (editorInput != null) {
IPath filePath = getSourceFilePathFromEditorInput(editorInput);
if (filePath != null) {
return filePath.toOSString();
}
}
}
}
}
Expand Down

0 comments on commit 8c3df8b

Please sign in to comment.