|
17 | 17 | import com.magento.idea.magento2plugin.actions.generation.ModuleObserverData; |
18 | 18 | import com.magento.idea.magento2plugin.actions.generation.data.ObserverEventsXmlData; |
19 | 19 | import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; |
| 20 | +import com.magento.idea.magento2plugin.actions.generation.dialog.reflection.GetReflectionFieldUtil; |
20 | 21 | import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation; |
21 | 22 | import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry; |
22 | 23 | import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule; |
|
37 | 38 | import java.awt.event.KeyEvent; |
38 | 39 | import java.awt.event.WindowAdapter; |
39 | 40 | import java.awt.event.WindowEvent; |
| 41 | +import java.lang.reflect.Field; |
40 | 42 | import java.util.ArrayList; |
41 | 43 | import java.util.Collection; |
42 | 44 | import java.util.List; |
@@ -239,27 +241,34 @@ protected void onOK() { |
239 | 241 |
|
240 | 242 | private boolean validateFields() { |
241 | 243 | final PsiFile[] directoryFiles = getDirectoryFiles(baseDir); |
| 244 | + final Field classNameField = GetReflectionFieldUtil.getByName("className", this.getClass()); |
242 | 245 |
|
243 | | - if (directoryFiles != null) { |
| 246 | + if (directoryFiles != null && classNameField != null) { |
244 | 247 | for (final PsiFile file : directoryFiles) { |
245 | 248 | final String className = ModuleObserverFile.resolveClassNameFromInput( |
246 | 249 | getClassName() |
247 | 250 | ); |
| 251 | + |
248 | 252 | if (file.getName().equals(className + ModuleObserverFile.EXTENSION)) { |
249 | 253 | showErrorMessage( |
250 | | - fieldsValidationsList.get(1).getField(), |
| 254 | + classNameField, |
251 | 255 | "Class name " + className + " already exist." |
252 | 256 | ); |
253 | 257 |
|
254 | 258 | return false; |
255 | 259 | } |
256 | 260 | } |
257 | 261 | } |
258 | | - if (!getDirectoryStructure().isEmpty() |
| 262 | + final Field directoryStructureField = GetReflectionFieldUtil.getByName( |
| 263 | + "directoryStructure", |
| 264 | + this.getClass() |
| 265 | + ); |
| 266 | + |
| 267 | + if (!getDirectoryStructure().isEmpty() && directoryStructureField != null |
259 | 268 | && !DirectoryRule.getInstance().check(getDirectoryStructure()) |
260 | 269 | ) { |
261 | 270 | showErrorMessage( |
262 | | - this.getClass().getDeclaredFields()[11], |
| 271 | + directoryStructureField, |
263 | 272 | "The Directory Path field does not contain a valid directory." |
264 | 273 | ); |
265 | 274 |
|
|
0 commit comments