15
15
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
16
16
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .PhpClassRule ;
17
17
import com .magento .idea .magento2plugin .actions .generation .generator .ModuleSetupDataPatchGenerator ;
18
+ import com .magento .idea .magento2plugin .actions .generation .generator .util .DirectoryGenerator ;
18
19
import com .magento .idea .magento2plugin .magento .files .ModuleSetupDataPatchFile ;
20
+ import com .magento .idea .magento2plugin .magento .packages .File ;
19
21
import java .awt .event .ActionEvent ;
20
22
import java .awt .event .KeyEvent ;
21
23
import java .awt .event .WindowAdapter ;
22
24
import java .awt .event .WindowEvent ;
23
- import java .util .Objects ;
24
25
import javax .swing .JButton ;
25
26
import javax .swing .JComponent ;
26
27
import javax .swing .JLabel ;
@@ -128,11 +129,15 @@ protected void onOK() {
128
129
}
129
130
130
131
private void generateFile () {
132
+ final PsiDirectory directory = DirectoryGenerator .getInstance ().findOrCreateSubdirectories (
133
+ baseDir , NewSetupDataPatchAction .PATCH_DIRECTORY + File .separator
134
+ + NewSetupDataPatchAction .DATA_DIRECTORY
135
+ );
131
136
final ModuleSetupDataPatchGenerator generator = new ModuleSetupDataPatchGenerator (
132
137
new ModuleSetupDataPatchData (
133
138
modulePackage ,
134
139
moduleName ,
135
- createDirectory ( baseDir ) ,
140
+ directory ,
136
141
getClassName ()
137
142
),
138
143
project
@@ -146,16 +151,22 @@ public String getClassName() {
146
151
}
147
152
148
153
private boolean validateFields () {
149
- final PsiDirectory targetDirectory = getDirectory (baseDir );
154
+ final PsiDirectory patchDirectory = baseDir .findSubdirectory (
155
+ NewSetupDataPatchAction .PATCH_DIRECTORY
156
+ );
157
+ PsiDirectory directory = null ;
150
158
151
- if (NewSetupDataPatchAction .DATA_DIRECTORY .equals (targetDirectory .getName ())) {
152
- final PsiFile [] files = targetDirectory .getFiles ();
153
- for (final PsiFile file : files ) {
159
+ if (patchDirectory != null ) {
160
+ directory = patchDirectory .findSubdirectory (NewSetupDataPatchAction .DATA_DIRECTORY );
161
+ }
162
+
163
+ if (directory != null ) {
164
+ for (final PsiFile file : directory .getFiles ()) {
154
165
final String className = ModuleSetupDataPatchFile .resolveClassNameFromInput (
155
166
getClassName ()
156
167
);
157
168
158
- if (file .getName ().equals (className + ".php" )) {
169
+ if (file .getName ().equals (className + ModuleSetupDataPatchFile . EXTENSION )) {
159
170
showErrorMessage (
160
171
fieldsValidationsList .get (0 ).getField (),
161
172
"Class name `" + className + "` already exist."
@@ -165,59 +176,7 @@ private boolean validateFields() {
165
176
}
166
177
}
167
178
}
168
- return validateFormFields ();
169
- }
170
-
171
- private PsiDirectory getDirectory (final PsiDirectory targetDirectory ) {
172
- if (NewSetupDataPatchAction .ROOT_DIRECTORY .equals (baseDir .getName ())) {
173
- final PsiDirectory subDirectoryPatch = baseDir .findSubdirectory (
174
- NewSetupDataPatchAction .PATCH_DIRECTORY
175
- );
176
179
177
- if (subDirectoryPatch != null ) {
178
- return subDirectoryPatch .findSubdirectory (NewSetupDataPatchAction .DATA_DIRECTORY );
179
- }
180
- }
181
- if (NewSetupDataPatchAction .PATCH_DIRECTORY .equals (baseDir .getName ())) {
182
- return baseDir .findSubdirectory (NewSetupDataPatchAction .DATA_DIRECTORY );
183
- }
184
-
185
- return targetDirectory ;
186
- }
187
-
188
- private PsiDirectory createDirectory (final PsiDirectory targetDirectory ) {
189
- if (NewSetupDataPatchAction .ROOT_DIRECTORY .equals (targetDirectory .getName ())) {
190
- final PsiDirectory subDirectoryPatch = targetDirectory .findSubdirectory (
191
- NewSetupDataPatchAction .PATCH_DIRECTORY
192
- );
193
-
194
- if (subDirectoryPatch == null ) {
195
- return targetDirectory .createSubdirectory (
196
- NewSetupDataPatchAction .PATCH_DIRECTORY
197
- ).createSubdirectory (NewSetupDataPatchAction .DATA_DIRECTORY );
198
- }
199
- final PsiDirectory subDirectoryData = subDirectoryPatch .findSubdirectory (
200
- NewSetupDataPatchAction .DATA_DIRECTORY
201
- );
202
-
203
- return Objects .requireNonNullElseGet (
204
- subDirectoryData , () -> subDirectoryPatch .createSubdirectory (
205
- NewSetupDataPatchAction .DATA_DIRECTORY
206
- )
207
- );
208
- }
209
- if (NewSetupDataPatchAction .PATCH_DIRECTORY .equals (targetDirectory .getName ())) {
210
- final PsiDirectory subDirectoryData = targetDirectory .findSubdirectory (
211
- NewSetupDataPatchAction .DATA_DIRECTORY
212
- );
213
-
214
- return Objects .requireNonNullElseGet (
215
- subDirectoryData , () -> targetDirectory .createSubdirectory (
216
- NewSetupDataPatchAction .DATA_DIRECTORY
217
- )
218
- );
219
- }
220
-
221
- return targetDirectory ;
180
+ return validateFormFields ();
222
181
}
223
182
}
0 commit comments