Skip to content

Commit d93bca8

Browse files
committed
1139: Fixed code
1 parent c07bf4f commit d93bca8

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.magento.idea.magento2plugin.actions.generation.ModuleObserverData;
1818
import com.magento.idea.magento2plugin.actions.generation.data.ObserverEventsXmlData;
1919
import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData;
20+
import com.magento.idea.magento2plugin.actions.generation.dialog.reflection.GetReflectionFieldUtil;
2021
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
2122
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
2223
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule;
@@ -37,6 +38,7 @@
3738
import java.awt.event.KeyEvent;
3839
import java.awt.event.WindowAdapter;
3940
import java.awt.event.WindowEvent;
41+
import java.lang.reflect.Field;
4042
import java.util.ArrayList;
4143
import java.util.Collection;
4244
import java.util.List;
@@ -239,27 +241,34 @@ protected void onOK() {
239241

240242
private boolean validateFields() {
241243
final PsiFile[] directoryFiles = getDirectoryFiles(baseDir);
244+
final Field classNameField = GetReflectionFieldUtil.getByName("className", this.getClass());
242245

243-
if (directoryFiles != null) {
246+
if (directoryFiles != null && classNameField != null) {
244247
for (final PsiFile file : directoryFiles) {
245248
final String className = ModuleObserverFile.resolveClassNameFromInput(
246249
getClassName()
247250
);
251+
248252
if (file.getName().equals(className + ModuleObserverFile.EXTENSION)) {
249253
showErrorMessage(
250-
fieldsValidationsList.get(1).getField(),
254+
classNameField,
251255
"Class name " + className + " already exist."
252256
);
253257

254258
return false;
255259
}
256260
}
257261
}
258-
if (!getDirectoryStructure().isEmpty()
262+
final Field directoryStructureField = GetReflectionFieldUtil.getByName(
263+
"directoryStructure",
264+
this.getClass()
265+
);
266+
267+
if (!getDirectoryStructure().isEmpty() && directoryStructureField != null
259268
&& !DirectoryRule.getInstance().check(getDirectoryStructure())
260269
) {
261270
showErrorMessage(
262-
this.getClass().getDeclaredFields()[11],
271+
directoryStructureField,
263272
"The Directory Path field does not contain a valid directory."
264273
);
265274

0 commit comments

Comments
 (0)