13
13
import com .magento .idea .magento2plugin .magento .packages .ComponentType ;
14
14
import com .magento .idea .magento2plugin .magento .packages .Package ;
15
15
import com .magento .idea .magento2plugin .util .magento .GetMagentoModuleUtil ;
16
- import java .util .Objects ;
17
16
import org .jetbrains .annotations .NotNull ;
18
17
19
18
public class NewSetupDataPatchAction extends CustomGeneratorContextAction {
20
19
21
20
public static final String ACTION_NAME = "Magento 2 Setup Data Patch" ;
22
21
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Setup Data Patch" ;
23
- public static final String ROOT_DIRECTORY = "Setup" ;
22
+ public static final String SETUP_DIRECTORY = "Setup" ;
24
23
public static final String PATCH_DIRECTORY = "Patch" ;
25
24
public static final String DATA_DIRECTORY = "Data" ;
26
25
@@ -40,11 +39,14 @@ public void actionPerformed(final @NotNull AnActionEvent event) {
40
39
if (module .length != 2 ) { //NOPMD
41
40
return ;
42
41
}
43
- final PsiDirectory rooDirectory = moduleData .getModuleDir ().findSubdirectory (
44
- ROOT_DIRECTORY
42
+ final PsiDirectory rootDirectory = moduleData .getModuleDir ().findSubdirectory (
43
+ SETUP_DIRECTORY
45
44
);
46
45
47
- NewSetupDataPatchDialog .open (event .getProject (), rooDirectory , module [0 ], module [1 ]);
46
+ if (rootDirectory == null ) {
47
+ return ;
48
+ }
49
+ NewSetupDataPatchDialog .open (event .getProject (), rootDirectory , module [0 ], module [1 ]);
48
50
}
49
51
50
52
@ Override
@@ -57,28 +59,30 @@ protected boolean isVisible(
57
59
return false ;
58
60
}
59
61
60
- if (ROOT_DIRECTORY .equals (targetDirectory .getName ())) {
61
- return Objects .requireNonNull (targetDirectory .getParentDirectory ()).getName ().equals (
62
- moduleData .getModuleDir ().getName ()
63
- );
62
+ if (SETUP_DIRECTORY .equals (targetDirectory .getName ())) {
63
+ return moduleData .getModuleDir ().equals (targetDirectory .getParentDirectory ());
64
64
}
65
65
66
66
if (PATCH_DIRECTORY .equals (targetDirectory .getName ())) {
67
- return ROOT_DIRECTORY .equals (Objects .requireNonNull (
68
- targetDirectory .getParentDirectory ()).getName ()
69
- );
67
+ final PsiDirectory setupDirCandidate = targetDirectory .getParentDirectory ();
68
+
69
+ return setupDirCandidate != null
70
+ && SETUP_DIRECTORY .equals (setupDirCandidate .getName ())
71
+ && moduleData .getModuleDir ().equals (setupDirCandidate .getParentDirectory ());
70
72
}
71
73
72
74
if (DATA_DIRECTORY .equals (targetDirectory .getName ())) {
73
- final PsiDirectory parentDirectory = Objects .requireNonNull (
74
- targetDirectory .getParentDirectory ()
75
- );
76
-
77
- if (PATCH_DIRECTORY .equals (parentDirectory .getName ())) {
78
- return ROOT_DIRECTORY .equals (Objects .requireNonNull (
79
- parentDirectory .getParentDirectory ()).getName ()
80
- );
75
+ final PsiDirectory patchDirCandidate = targetDirectory .getParentDirectory ();
76
+
77
+ if (patchDirCandidate == null ) {
78
+ return false ;
81
79
}
80
+ final PsiDirectory setupDirCandidate = patchDirCandidate .getParentDirectory ();
81
+
82
+ return setupDirCandidate != null
83
+ && PATCH_DIRECTORY .equals (patchDirCandidate .getName ())
84
+ && SETUP_DIRECTORY .equals (setupDirCandidate .getName ())
85
+ && moduleData .getModuleDir ().equals (setupDirCandidate .getParentDirectory ());
82
86
}
83
87
84
88
return false ;
0 commit comments