44import com .intellij .openapi .module .Module ;
55import com .intellij .openapi .project .Project ;
66import com .intellij .openapi .roots .ModuleRootManager ;
7+ import com .intellij .openapi .roots .ProjectRootManager ;
78import com .intellij .openapi .ui .Messages ;
89import com .intellij .openapi .vfs .VirtualFile ;
910import com .intellij .pom .Navigatable ;
3031import java .awt .event .ComponentEvent ;
3132import java .util .List ;
3233
33- public class ClassFromJSONAction extends AnAction implements JSONEditDialog .JSONEditCallbacks , ModelTableDialog .ModelTableCallbacks {
34+ public class ClassFromJSONAction extends AnAction implements JSONEditDialog .JSONEditCallbacks ,
35+ ModelTableDialog .ModelTableCallbacks {
3436
3537 private PsiDirectory directory ;
3638 private Point lastDialogLocation ;
@@ -49,20 +51,21 @@ public void actionPerformed(AnActionEvent event) {
4951 Project project = event .getProject ();
5052 if (project == null ) return ;
5153 DataContext dataContext = event .getDataContext ();
52- final Module module = DataKeys .MODULE .getData (dataContext );
53- if (module == null ) return ;
54- final Navigatable navigatable = DataKeys .NAVIGATABLE .getData (dataContext );
54+ final Navigatable navigatable = PlatformDataKeys .NAVIGATABLE .getData (dataContext );
5555
5656 if (navigatable != null ) {
5757 if (navigatable instanceof PsiDirectory ) {
5858 directory = (PsiDirectory ) navigatable ;
59- }
60- }
61-
62- if (directory == null ) {
63- ModuleRootManager root = ModuleRootManager .getInstance (module );
64- for (VirtualFile file : root .getSourceRoots ()) {
65- directory = PsiManager .getInstance (project ).findDirectory (file );
59+ } else {
60+ final VirtualFile projectFile = project .getProjectFile ();
61+ if (projectFile == null ) throw new NullPointerException ("Project file not found" );
62+ Module module = ProjectRootManager .getInstance (project ).getFileIndex ().getModuleForFile (projectFile );
63+ if (module !=null ){
64+ ModuleRootManager root = ModuleRootManager .getInstance (module );
65+ for (VirtualFile file : root .getSourceRoots ()) {
66+ directory = PsiManager .getInstance (project ).findDirectory (file );
67+ }
68+ }
6669 }
6770 }
6871
0 commit comments