package com.reason.ide.format;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;

import static com.intellij.openapi.actionSystem.CommonDataKeys.PSI_FILE;

public class RefmtAction extends AnAction {
    @Override
    public void actionPerformed(AnActionEvent e) {
        RefmtManager instance = RefmtManager.getInstance();
        if (instance != null) {
            PsiFile data = e.getData(PSI_FILE);
            Document document = PsiDocumentManager.getInstance(e.getProject()).getDocument(data);
            ApplicationManager.getApplication().runWriteAction(() -> instance.refmt(document));
        }
    }
}

@@ -233,24 +233,69 @@
 r.Document;%0A
+import com.intellij.openapi.project.Project;%0A
 import com.i
@@ -683,16 +683,117 @@
 _FILE);%0A
+            Project project = e.getProject();%0A            if (project != null && data != null) %7B%0A    
         
@@ -847,30 +847,23 @@
 nstance(
-e.getP
+p
 roject
-()
 ).getDoc
@@ -887,16 +887,20 @@
         
+  
+  
 Applicat
@@ -975,16 +975,30 @@
 ment));%0A
+            %7D%0A
         

Remove a NullPointerException