4
4
import com .intellij .openapi .module .Module ;
5
5
import com .intellij .openapi .project .Project ;
6
6
import com .intellij .openapi .roots .ModuleRootManager ;
7
+ import com .intellij .openapi .roots .ProjectRootManager ;
7
8
import com .intellij .openapi .ui .Messages ;
8
9
import com .intellij .openapi .vfs .VirtualFile ;
9
10
import com .intellij .pom .Navigatable ;
30
31
import java .awt .event .ComponentEvent ;
31
32
import java .util .List ;
32
33
33
- public class ClassFromJSONAction extends AnAction implements JSONEditDialog .JSONEditCallbacks , ModelTableDialog .ModelTableCallbacks {
34
+ public class ClassFromJSONAction extends AnAction implements JSONEditDialog .JSONEditCallbacks ,
35
+ ModelTableDialog .ModelTableCallbacks {
34
36
35
37
private PsiDirectory directory ;
36
38
private Point lastDialogLocation ;
@@ -49,20 +51,21 @@ public void actionPerformed(AnActionEvent event) {
49
51
Project project = event .getProject ();
50
52
if (project == null ) return ;
51
53
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 );
55
55
56
56
if (navigatable != null ) {
57
57
if (navigatable instanceof PsiDirectory ) {
58
58
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
+ }
66
69
}
67
70
}
68
71
0 commit comments