From d1fc42783862c2f5e7f1cacf277b66af98021d51 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Tue, 18 Feb 2025 20:55:54 +0200 Subject: [PATCH 01/11] 2490: Remove SlowOperations API and deprecated behaviors Refactor code to remove usage of the SlowOperations API for resolving references and retrieving data, improving performance and aligning with the latest IntelliJ guidelines. Additionally, deprecated methods and hardcoded Magento directory prompts were removed, and notification handling was updated to use modern APIs. --- gradle.properties | 2 +- .../generation/CreateAnObserverAction.java | 3 +-- .../php/MagentoModuleGenerator.java | 6 ----- .../generation/php/NewModuleForm.java | 2 -- .../magento2plugin/indexes/ModuleIndex.java | 23 ++++++++----------- ...plementsNoninterceptableInterfaceUtil.java | 5 +--- .../project/ProjectDetector.java | 11 ++++++--- .../magento2plugin/project/SettingsForm.java | 2 -- .../util/magento/GetMagentoModuleUtil.java | 5 +--- 9 files changed, 22 insertions(+), 37 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6a043348b..0c99b4089 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ pluginName = Magento PhpStorm pluginRepositoryUrl = https://github.com/magento/magento2-phpstorm-plugin pluginVersion = 5.4.0 pluginSinceBuild = 233 -pluginUntilBuild = 248.* +pluginUntilBuild = 258.* platformType = PS platformVersion = 2024.3 platformPlugins = diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/CreateAnObserverAction.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/CreateAnObserverAction.java index c829bd732..92a5e3276 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/CreateAnObserverAction.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/CreateAnObserverAction.java @@ -17,7 +17,6 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiReference; import com.intellij.psi.tree.IElementType; -import com.intellij.util.SlowOperations; import com.jetbrains.php.lang.lexer.PhpTokenTypes; import com.jetbrains.php.lang.psi.PhpFile; import com.jetbrains.php.lang.psi.elements.Method; @@ -133,7 +132,7 @@ private boolean checkIsEventDispatchMethod(final MethodReference element) { if (elementReference == null) { return false; } - final PsiElement method = SlowOperations.allowSlowOperations(elementReference::resolve); + final PsiElement method = elementReference.resolve(); if (!(method instanceof Method)) { return false; } diff --git a/src/main/java/com/magento/idea/magento2plugin/generation/php/MagentoModuleGenerator.java b/src/main/java/com/magento/idea/magento2plugin/generation/php/MagentoModuleGenerator.java index b6c9d669b..9dfe5796d 100644 --- a/src/main/java/com/magento/idea/magento2plugin/generation/php/MagentoModuleGenerator.java +++ b/src/main/java/com/magento/idea/magento2plugin/generation/php/MagentoModuleGenerator.java @@ -15,7 +15,6 @@ import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; -import com.intellij.util.PlatformUtils; import com.magento.idea.magento2plugin.MagentoIcons; import com.magento.idea.magento2plugin.actions.generation.data.ModuleComposerJsonData; import com.magento.idea.magento2plugin.actions.generation.data.ModuleRegistrationPhpData; @@ -57,11 +56,6 @@ public ProjectGeneratorPeer createPeer() { return new MagentoProjectPeer(); } - @Override - public boolean isPrimaryGenerator() { - return PlatformUtils.isPhpStorm(); - } - /** * Generate project. * diff --git a/src/main/java/com/magento/idea/magento2plugin/generation/php/NewModuleForm.java b/src/main/java/com/magento/idea/magento2plugin/generation/php/NewModuleForm.java index b247d3dfa..9148328aa 100644 --- a/src/main/java/com/magento/idea/magento2plugin/generation/php/NewModuleForm.java +++ b/src/main/java/com/magento/idea/magento2plugin/generation/php/NewModuleForm.java @@ -79,8 +79,6 @@ private void addPathListener() { FileChooserDescriptorFactory.createSingleFolderDescriptor(); final ComponentWithBrowseButton.BrowseFolderActionListener browseFolderListener = new ComponentWithBrowseButton.BrowseFolderActionListener( - "Magento Root Directory", - "Choose Magento root directory", this.magentoPath, null, descriptor, diff --git a/src/main/java/com/magento/idea/magento2plugin/indexes/ModuleIndex.java b/src/main/java/com/magento/idea/magento2plugin/indexes/ModuleIndex.java index f71d648c5..9effedd69 100644 --- a/src/main/java/com/magento/idea/magento2plugin/indexes/ModuleIndex.java +++ b/src/main/java/com/magento/idea/magento2plugin/indexes/ModuleIndex.java @@ -12,7 +12,6 @@ import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiManager; import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.util.SlowOperations; import com.intellij.util.indexing.FileBasedIndex; import com.jetbrains.php.lang.PhpFileType; import com.magento.idea.magento2plugin.magento.packages.Package; @@ -128,18 +127,16 @@ private List getNames( .getInstance(); final Collection files = new ArrayList<>(); - SlowOperations.allowSlowOperations(() -> { - files.addAll( - index.getContainingFiles( - ModuleNameIndex.KEY, - moduleName, - GlobalSearchScope.getScopeRestrictedByFileTypes( - GlobalSearchScope.allScope(project), - PhpFileType.INSTANCE - ) - ) - ); - }); + files.addAll( + index.getContainingFiles( + ModuleNameIndex.KEY, + moduleName, + GlobalSearchScope.getScopeRestrictedByFileTypes( + GlobalSearchScope.allScope(project), + PhpFileType.INSTANCE + ) + ) + ); if (files.isEmpty()) { return null; diff --git a/src/main/java/com/magento/idea/magento2plugin/inspections/php/util/PhpClassImplementsNoninterceptableInterfaceUtil.java b/src/main/java/com/magento/idea/magento2plugin/inspections/php/util/PhpClassImplementsNoninterceptableInterfaceUtil.java index 1f611196d..8d7360966 100644 --- a/src/main/java/com/magento/idea/magento2plugin/inspections/php/util/PhpClassImplementsNoninterceptableInterfaceUtil.java +++ b/src/main/java/com/magento/idea/magento2plugin/inspections/php/util/PhpClassImplementsNoninterceptableInterfaceUtil.java @@ -5,7 +5,6 @@ package com.magento.idea.magento2plugin.inspections.php.util; -import com.intellij.util.SlowOperations; import com.jetbrains.php.lang.psi.elements.PhpClass; import com.magento.idea.magento2plugin.magento.files.Plugin; import org.jetbrains.annotations.NotNull; @@ -22,9 +21,7 @@ private PhpClassImplementsNoninterceptableInterfaceUtil() {} * @return bool */ public static boolean execute(final @NotNull PhpClass phpClass) { - final PhpClass[] interfaces = SlowOperations.allowSlowOperations( - phpClass::getImplementedInterfaces - ); + final PhpClass[] interfaces = phpClass.getImplementedInterfaces(); if (interfaces.length == 0) { return false; diff --git a/src/main/java/com/magento/idea/magento2plugin/project/ProjectDetector.java b/src/main/java/com/magento/idea/magento2plugin/project/ProjectDetector.java index c80f5f1a9..9a6876066 100644 --- a/src/main/java/com/magento/idea/magento2plugin/project/ProjectDetector.java +++ b/src/main/java/com/magento/idea/magento2plugin/project/ProjectDetector.java @@ -5,6 +5,7 @@ package com.magento.idea.magento2plugin.project; +import com.intellij.notification.NotificationGroupManager; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; @@ -36,9 +37,13 @@ public void configureProject( if (!MagentoBasePathUtil.isMagentoFolderValid(baseDir.getPath())) { return; } - final Notification notification = new Notification("Magento", "Magento", - "Enable Magento support for this project?", - NotificationType.INFORMATION, new NotificationListener.Adapter() { + final Notification notification = NotificationGroupManager.getInstance() + .getNotificationGroup("Magento Notifications") + .createNotification( + "Magento", + "Enable Magento support for this project?", + NotificationType.INFORMATION + ).setListener(new NotificationListener.Adapter() { @Override public void hyperlinkActivated( final @NotNull Notification notification, diff --git a/src/main/java/com/magento/idea/magento2plugin/project/SettingsForm.java b/src/main/java/com/magento/idea/magento2plugin/project/SettingsForm.java index 55f747bf6..eb1d5d33e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/project/SettingsForm.java +++ b/src/main/java/com/magento/idea/magento2plugin/project/SettingsForm.java @@ -195,8 +195,6 @@ private void addPathListener() { FileChooserDescriptorFactory.createSingleFolderDescriptor(); final ComponentWithBrowseButton.BrowseFolderActionListener browseFolderListener = new ComponentWithBrowseButton.BrowseFolderActionListener( - "Magento Root Directory", - "Choose Magento root directory", this.magentoPath, project, descriptor, diff --git a/src/main/java/com/magento/idea/magento2plugin/util/magento/GetMagentoModuleUtil.java b/src/main/java/com/magento/idea/magento2plugin/util/magento/GetMagentoModuleUtil.java index 3c4541f34..e38c30395 100644 --- a/src/main/java/com/magento/idea/magento2plugin/util/magento/GetMagentoModuleUtil.java +++ b/src/main/java/com/magento/idea/magento2plugin/util/magento/GetMagentoModuleUtil.java @@ -10,7 +10,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.util.SlowOperations; import com.jetbrains.php.lang.psi.elements.ClassConstantReference; import com.jetbrains.php.lang.psi.elements.MethodReference; import com.jetbrains.php.lang.psi.elements.StringLiteralExpression; @@ -140,9 +139,7 @@ private static PsiFile getModuleRegistrationFile( private static String parseParameterValue(final PsiElement valueHolder) { if (valueHolder instanceof ClassConstantReference) { final ClassConstantReference constantReference = (ClassConstantReference) valueHolder; - final PsiElement resolved = SlowOperations.allowSlowOperations( - constantReference::resolve - ); + final PsiElement resolved = constantReference.resolve(); if (!(resolved instanceof ClassConstImpl)) { return null; From 0df1a5b9713657bdb8af6ebe3c115aa3f784feff Mon Sep 17 00:00:00 2001 From: vitaliy Date: Wed, 19 Feb 2025 21:07:40 +0200 Subject: [PATCH 02/11] 2490: Update plugin to version 2025.0.1 with compatibility fix This release updates the plugin to version 2025.0.1 and includes a fix for compatibility with the 2025.* PhpStorm build range. Minor adjustments to plugin documentation and formatting were also applied for improved clarity and presentation. --- CHANGELOG.md | 6 ++ README.md | 57 ++++++++++++------- gradle.properties | 2 +- .../project/ProjectDetector.java | 2 +- src/main/resources/META-INF/plugin.xml | 44 +------------- 5 files changed, 44 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96792c157..a5973da03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). +## 2025.0.1 + +### Fixed + +- Fixed compatibility with 2025.* [#2495](https://github.com/magento/magento2-phpstorm-plugin/pull/2495) + ## 2025.0.0 ### Added diff --git a/README.md b/README.md index 6215b9cfa..16723678e 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,18 @@ # PhpStorm Magento 2 Plugin -This is a PhpStorm IDE plugin for a better Magento 2 development workflow. - -## Version 2025.0.0 - Contributors - + + + + + + + + + + + + +
+This is a PhpStorm IDE plugin for a better Magento 2 development workflow. +
+ Version 2025.0.0 - Contributors +
@@ -35,13 +42,33 @@ This is a PhpStorm IDE plugin for a better Magento 2 development workflow.
+

Support the Project

+

If you find this plugin helpful and want to support its development, consider buying the contributors a coffee:

+ + Buy Me a Coffee + +
-### Support the Project - -If you find this plugin helpful and want to support its development, consider buying the contributors a coffee: +## Features -[![Buy Me a Coffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-Donate-orange.svg)](https://buymeacoffee.com/vitalii_b) +* Configuration smart completion and references for XML/JavaScript files +* `Navigate to configuration` reference in scope of class/interface +* `Go to plugin` reference in scope of class/interface and method +* `Navigate to Web API configuration` reference in scope of class/interface and method +* Plugin class methods generation +* Plugin declaration inspection +* RequireJS reference navigation and completion +* MFTF reference navigation and completion +* GraphQL navigation line markers +* Code generation +* Inspections for XML configuration @@ -63,20 +90,6 @@ If you find this plugin helpful and want to support its development, consider bu * PhpStorm >= 2023.1 * JRE >= 17 -## Features - -* Configuration smart completion and references for XML/JavaScript files -* `Navigate to configuration` reference in scope of class/interface -* `Go to plugin` reference in scope of class/interface and method -* `Navigate to Web API configuration` reference in scope of class/interface and method -* Plugin class methods generation -* Plugin declaration inspection -* RequireJS reference navigation and completion -* MFTF reference navigation and completion -* GraphQL navigation line markers -* Code generation -* Inspections for XML configuration - ## Setting up development environment 1. Check out this repository diff --git a/gradle.properties b/gradle.properties index 86f26bfbd..8597e8be4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ pluginGroup = com.magento.idea.magento2plugin pluginName = Magento PhpStorm pluginRepositoryUrl = https://github.com/magento/magento2-phpstorm-plugin -pluginVersion = 2025.0.0 +pluginVersion = 2025.0.1 pluginSinceBuild = 233 pluginUntilBuild = 258.* platformType = PS diff --git a/src/main/java/com/magento/idea/magento2plugin/project/ProjectDetector.java b/src/main/java/com/magento/idea/magento2plugin/project/ProjectDetector.java index 9a6876066..a572d1adf 100644 --- a/src/main/java/com/magento/idea/magento2plugin/project/ProjectDetector.java +++ b/src/main/java/com/magento/idea/magento2plugin/project/ProjectDetector.java @@ -5,8 +5,8 @@ package com.magento.idea.magento2plugin.project; -import com.intellij.notification.NotificationGroupManager; import com.intellij.notification.Notification; +import com.intellij.notification.NotificationGroupManager; import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; import com.intellij.notification.Notifications; diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 6139a9b5e..f802f43ac 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -7,53 +7,11 @@ com.magento.idea.magento2plugin Magento PhpStorm - 2025.0.0 + 2025.0.1 Magento Inc. Main Features -
    -
  • Code Generation: Quickly generate boilerplate Magento code like plugins, observers, XML configurations, and more.
  • -
  • Inspections: Identify and fix potential issues with Magento-specific code quality tools.
  • -
  • Reference Navigation: Easily navigate between Magento files, classes, and references.
  • -
  • Code Completion: Auto-complete Magento-specific code constructs, including XML tags, class names, and methods.
  • -
  • Copy Magento Path: Copy file paths in Magento format.
  • -
  • Upgrade Compatibility Tool: Assist in upgrading Magento modules and code for newer Magento versions.
  • -
  • URN Mapping: Resolve Magento URNs for correct file associations and navigation.
  • -
-

Version 2025.0.0 - Contributors

- - - - - - -
- - Contributor 1 -
- Yevhen Zvieriev -
-
- - Contributor 2 -
- Mykola Silin -
-
- - Contributor 3 -
- Vitalii Boiko -
-
- -

Support the Project

- -If you find this plugin helpful and want to support its development, consider buying the contributors a coffee: -Buy Me a Coffee ]]>
Date: Wed, 19 Feb 2025 21:11:12 +0200 Subject: [PATCH 03/11] 2490: Update changelog entry for 2025.* compatibility fix Corrected the changelog to clarify compatibility with PhpStorm/IntelliJ 2025.* builds. This ensures the documentation accurately reflects the scope of the fix. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5973da03..3a1a26c0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). ### Fixed -- Fixed compatibility with 2025.* [#2495](https://github.com/magento/magento2-phpstorm-plugin/pull/2495) +- Fixed compatibility with PhpStorm/IntelliJ 2025.* [#2495](https://github.com/magento/magento2-phpstorm-plugin/pull/2495) ## 2025.0.0 From c8277f25a7b6a1fada03c6784a0c12fe960d5a50 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Thu, 20 Feb 2025 22:55:43 +0200 Subject: [PATCH 04/11] 2490: Refactor module name resolution and file indexing logic. Streamlined retrieval of module names and their associated files by consolidating logic into `FileBasedIndex` queries. Removed deprecated utility method usages, reducing unnecessary complexity and improving maintainability. --- .../actions/groups/NewModuleFileGroup.java | 37 +++++++++++++------ .../magento2plugin/indexes/ModuleIndex.java | 17 ++++----- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java b/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java index ac7ab20b8..326ee088f 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java @@ -10,14 +10,16 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiElement; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.util.indexing.FileBasedIndex; import com.magento.idea.magento2plugin.MagentoIcons; import com.magento.idea.magento2plugin.actions.generation.util.IsClickedDirectoryInsideProject; -import com.magento.idea.magento2plugin.indexes.ModuleIndex; import com.magento.idea.magento2plugin.project.Settings; -import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; -import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +import com.magento.idea.magento2plugin.stubs.indexes.ModuleNameIndex; +import java.util.Collection; public class NewModuleFileGroup extends NonTrivialActionGroup { @@ -50,20 +52,31 @@ public void update(final AnActionEvent event) { return; } - final String moduleName = GetModuleNameByDirectoryUtil - .execute((PsiDirectory) psiElement, project); + String moduleName = null; + VirtualFile psiDirectoryVirtualFile = ((PsiDirectory) psiElement).getVirtualFile(); - if (moduleName != null) { - final PsiDirectory moduleDirectory = new ModuleIndex(project) - .getModuleDirectoryByModuleName(moduleName); + for (var entry : FileBasedIndex.getInstance().getAllKeys(ModuleNameIndex.KEY, project)) { + Collection moduleVfs = FileBasedIndex.getInstance().getContainingFiles( + ModuleNameIndex.KEY, entry, GlobalSearchScope.projectScope(project) + ); + + for (VirtualFile moduleFile : moduleVfs) { + if (moduleFile.getParent().getPath().equals(psiDirectoryVirtualFile.getPath())) { + moduleName = entry; + break; + } + } - if (moduleDirectory != null - && GetMagentoModuleUtil.isDirectoryInEditableModule(moduleDirectory)) { - event.getPresentation().setVisible(true); - return; + if (moduleName != null) { + break; } } + if (moduleName != null) { + event.getPresentation().setVisible(true); + return; + } + event.getPresentation().setVisible(false); } } diff --git a/src/main/java/com/magento/idea/magento2plugin/indexes/ModuleIndex.java b/src/main/java/com/magento/idea/magento2plugin/indexes/ModuleIndex.java index 9effedd69..f3dfe5021 100644 --- a/src/main/java/com/magento/idea/magento2plugin/indexes/ModuleIndex.java +++ b/src/main/java/com/magento/idea/magento2plugin/indexes/ModuleIndex.java @@ -125,18 +125,15 @@ private List getNames( } final FileBasedIndex index = FileBasedIndex .getInstance(); - final Collection files = new ArrayList<>(); - files.addAll( - index.getContainingFiles( - ModuleNameIndex.KEY, - moduleName, - GlobalSearchScope.getScopeRestrictedByFileTypes( - GlobalSearchScope.allScope(project), - PhpFileType.INSTANCE - ) + final Collection files = new ArrayList<>(index.getContainingFiles( + ModuleNameIndex.KEY, + moduleName, + GlobalSearchScope.getScopeRestrictedByFileTypes( + GlobalSearchScope.allScope(project), + PhpFileType.INSTANCE ) - ); + )); if (files.isEmpty()) { return null; From f2fbfe11054ebae1ecedc496cbd9e3b13f65e21a Mon Sep 17 00:00:00 2001 From: vitaliy Date: Fri, 21 Feb 2025 20:35:12 +0200 Subject: [PATCH 05/11] 2490: Refactor dialog actions to run within WriteAction context Updated dialog action methods from `onOK` to `onWriteActionOK` and ensured execution through a centralized `executeOnOk` method. This improves thread safety by enforcing operations within the IDE's `WriteAction` context. Also added handling for exceptions during execution and support for dumb mode in `NewModuleFileGroup`. --- .../generation/dialog/AbstractDialog.java | 38 +++++++++++++++++++ .../dialog/CreateAPluginDialog.java | 3 +- .../dialog/CreateAnObserverDialog.java | 2 +- .../dialog/GatherArrayValuesDialog.java | 3 +- .../dialog/InjectAViewModelDialog.java | 3 +- .../dialog/NewArgumentInjectionDialog.java | 3 +- .../generation/dialog/NewBlockDialog.java | 3 +- .../dialog/NewCLICommandDialog.java | 3 +- .../dialog/NewControllerDialog.java | 3 +- .../generation/dialog/NewCronGroupDialog.java | 3 +- .../generation/dialog/NewCronjobDialog.java | 3 +- .../generation/dialog/NewDataModelDialog.java | 7 +++- .../generation/dialog/NewDbSchemaDialog.java | 3 +- .../dialog/NewEmailTemplateDialog.java | 3 +- .../generation/dialog/NewEntityDialog.java | 3 +- .../dialog/NewGraphQlResolverDialog.java | 3 +- .../dialog/NewInterfaceForServiceDialog.java | 3 +- .../dialog/NewLayoutTemplateDialog.java | 3 +- .../dialog/NewMessageQueueDialog.java | 3 +- .../generation/dialog/NewModelsDialog.java | 3 +- .../generation/dialog/NewModuleDialog.java | 3 +- .../generation/dialog/NewObserverDialog.java | 3 +- .../dialog/NewSetupDataPatchDialog.java | 3 +- .../dialog/NewUiComponentFormDialog.java | 3 +- .../dialog/NewUiComponentGridDialog.java | 3 +- .../generation/dialog/NewViewModelDialog.java | 3 +- .../dialog/NewWebApiDeclarationDialog.java | 3 +- .../OverrideClassByAPreferenceDialog.java | 3 +- .../dialog/OverrideLayoutInThemeDialog.java | 2 +- .../dialog/OverrideTemplateInThemeDialog.java | 3 +- .../eavattribute/EavAttributeDialog.java | 5 ++- .../actions/groups/NewModuleFileGroup.java | 6 +++ .../magento2uct/ui/ConfigurationDialog.java | 2 +- .../idea/magento2uct/ui/ReindexDialog.java | 2 +- 34 files changed, 109 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java index 1736a00a4..8200b0535 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java @@ -5,6 +5,7 @@ package com.magento.idea.magento2plugin.actions.generation.dialog; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.util.Pair; import com.magento.idea.magento2plugin.actions.generation.data.ui.ComboBoxItemData; import com.magento.idea.magento2plugin.actions.generation.dialog.prompt.PlaceholderInitializerUtil; @@ -75,6 +76,43 @@ protected void exit() { dispose(); } + /** + * Executes onOK within a WriteAction context. + */ + protected final void executeOnOk() { + WriteAction.run(() -> { + try { + onWriteActionOK(); + } catch (Exception e) { + handleOnOkException(e); + } + }); + } + + /** + * This method should contain the core logic for onOk. + * Subclasses can override to provide their implementation. + * Must be invoked via executeOnOk(). + */ + protected abstract void onWriteActionOK(); + + /** + * Handle any exceptions that are thrown during execution of the onOK logic. + * Default implementation logs or shows the exception. + * + * @param e the exception encountered + */ + protected void handleOnOkException(Exception e) { + e.printStackTrace(); + } + + /** + * Hook executed when the OK button is pressed. + */ + protected final void onOK() { + executeOnOk(); + } + /** * Validate all form fields. * diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java index 7e6cc0dbe..b532c0f70 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java @@ -170,7 +170,8 @@ private void fillTargetAreaOptions() { } } - protected void onOK() { + protected void onWriteActionOK() { + if (targetMethod == null) { targetMethod = getSelectedTargetMethod(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java index 223ecee01..9a25ece3c 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java @@ -149,7 +149,7 @@ private void fillTargetAreaOptions() { /** * Perform code generation using input data. */ - private void onOK() { + protected void onWriteActionOK() { if (validateFormFields()) { new ObserverClassGenerator(new ObserverFileData( getObserverDirectory(), diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java index b27a371be..df2746624 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java @@ -114,7 +114,8 @@ public static void open( /** * Fire process if all fields are valid. */ - private void onOK() { + protected void onWriteActionOK() { + if (itemsTable.isEditing()) { itemsTable.getCellEditor().stopCellEditing(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java index c51c5ecca..234550bb9 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java @@ -136,7 +136,8 @@ protected void updateArgumentText() { ); } - protected void onOK() { + protected void onWriteActionOK() { + if (!validateFormFields()) { exit(); return; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.java index 16dab90f7..adc60b35b 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewArgumentInjectionDialog.java @@ -363,7 +363,8 @@ public static void open( /** * Fire generation process if all fields are valid. */ - private void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { final DiArgumentData data = getDialogDataObject(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java index 44342993a..3dac3f064 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java @@ -111,7 +111,8 @@ public static void open(final Project project, final PsiDirectory directory) { dialog.setVisible(true); } - protected void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { generateFile(); exit(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java index 26a085f41..c2e4c513b 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java @@ -190,7 +190,8 @@ public String getCLICommandClassFqn() { return namespaceBuilder.getClassFqn(); } - private void onOK() { + protected void onWriteActionOK() { + if (validateFormFields() && isPHPClassValid()) { this.generate(); exit(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java index 402cedb96..79f67c63a 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java @@ -198,7 +198,8 @@ public static void open(final Project project, final PsiDirectory directory) { dialog.setVisible(true); } - private void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { generateFile(); exit(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java index 28ddbd615..37dddae97 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java @@ -141,7 +141,8 @@ public static void open(final Project project, final PsiDirectory directory) { dialog.setVisible(true); } - private void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { generateFile(); exit(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java index a8f71b0f1..b8080691d 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java @@ -289,7 +289,8 @@ private String suggestCronjobName(final String cronjobClassname) { /** * When new cronjob dialog is filled, validate the input data and generate a new cronjob. */ - private void onOK() { + protected void onWriteActionOK() { + if (!validateFormFields()) { return; } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java index 9f1db8128..142382628 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java @@ -5,9 +5,13 @@ package com.magento.idea.magento2plugin.actions.generation.dialog; +import com.intellij.openapi.application.ReadAction; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBoxTableRenderer; import com.intellij.psi.PsiDirectory; +import com.intellij.util.RunnableCallable; +import com.intellij.util.concurrency.AppExecutorUtil; import com.magento.idea.magento2plugin.actions.generation.NewDataModelAction; import com.magento.idea.magento2plugin.actions.generation.OverrideClassByAPreferenceAction; import com.magento.idea.magento2plugin.actions.generation.data.DataModelData; @@ -140,7 +144,8 @@ public static void open( /** * Proceed with generation. */ - private void onOK() { + protected void onWriteActionOK() { + if (propertyTable.isEditing()) { propertyTable.getCellEditor().stopCellEditing(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java index 020b17443..fa946e778 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDbSchemaDialog.java @@ -133,7 +133,8 @@ public void windowClosing(final WindowEvent event) { /** * On buttonOK action listener. */ - private void onOK() { + protected void onWriteActionOK() { + if (columnsTable.isEditing()) { columnsTable.getCellEditor().stopCellEditing(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java index f2e463ce0..70ba3bdfa 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEmailTemplateDialog.java @@ -212,7 +212,8 @@ private String getModuleName() { return this.moduleName; } - private void onOK() { + protected void onWriteActionOK() { + final boolean emailTemplateCanBeDeclared = !this.validator.validate(this); if (!validateFormFields() || emailTemplateCanBeDeclared) { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java index 43dc7e6d0..1c78bdb2c 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java @@ -393,7 +393,8 @@ private void generateNewEntityFiles(final @NotNull ActionEvent event) { /** * Perform code generation using input data. */ - private void onOK() { + protected void onWriteActionOK() { + if (!validateFormFields()) { onOkActionFired.setInProgress(false); return; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java index 83b6080cf..59e2c088b 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java @@ -121,7 +121,8 @@ public static void open(final Project project, final PsiDirectory directory) { } } - protected void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { generateFile(); exit(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java index 7f4f45ee3..4c7c43314 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewInterfaceForServiceDialog.java @@ -169,7 +169,8 @@ private void fillPredefinedValuesAndDisableInputs() { /** * Fire generation process if all fields are valid. */ - private void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { final WebApiInterfaceData data = getDialogDataObject(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java index ded318d15..d7493efd6 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java @@ -103,7 +103,8 @@ public static void open(final Project project, final PsiDirectory directory) { dialog.setVisible(true); } - private void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { final String[] layoutNameParts = getLayoutNameParts(); final LayoutXmlData layoutXmlData = new LayoutXmlData( diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java index a309b58c2..d2d651989 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java @@ -255,7 +255,8 @@ public static void open( dialog.setVisible(true); } - private void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { generateCommunication(); generateConsumer(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java index 6157b0a21..b4f41c25c 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModelsDialog.java @@ -172,7 +172,8 @@ public static void open( /** * Process generation. */ - private void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { generateModelFile(); generateResourceModelFile(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java index 729d2d0c8..1ed2bd046 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java @@ -178,7 +178,8 @@ private void detectPackageName(final @NotNull PsiDirectory initialBaseDir) { } } - protected void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { generateFiles(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java index b1017e2d0..533e6ef30 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewObserverDialog.java @@ -198,7 +198,8 @@ public String getDirectoryStructure() { return directoryStructure.getText().trim(); } - protected void onOK() { + protected void onWriteActionOK() { + if (validateFields()) { PsiDirectory observerDirectory = baseDir; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java index babceb891..3f1cee92a 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java @@ -113,7 +113,8 @@ public static void open( /** * Fire generation process if all fields are valid. */ - protected void onOK() { + protected void onWriteActionOK() { + if (validateFields()) { generateFile(); exit(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java index ed9d470fd..5417a00e7 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentFormDialog.java @@ -423,7 +423,8 @@ public static void open( dialog.setVisible(true); } - private void onOK() { + protected void onWriteActionOK() { + if (formButtons.isEditing()) { formButtons.getCellEditor().stopCellEditing(); } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java index b8e568bfd..568870bc9 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewUiComponentGridDialog.java @@ -321,7 +321,8 @@ protected void onCancel() { dispose(); } - private void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { generateViewControllerFile(); generateLayoutFile(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java index 283004fa2..02c0e3365 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewViewModelDialog.java @@ -120,7 +120,8 @@ public static void open(final Project project, final PsiDirectory directory) { dialog.setVisible(true); } - protected void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { generateFile(); exit(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java index 84a361ae4..6544a8fa5 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewWebApiDeclarationDialog.java @@ -140,7 +140,8 @@ public static void open( /** * Fire generation process if all fields are valid. */ - private void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { new WebApiDeclarationGenerator( getDialogDataObject(), diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java index 451e91ea9..157f3b65a 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideClassByAPreferenceDialog.java @@ -166,7 +166,8 @@ private void fillTargetAreaOptions() { } } - protected void onOK() { + protected void onWriteActionOK() { + if (!validateFormFields()) { exit(); return; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java index 727f1363d..9144a0d5e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideLayoutInThemeDialog.java @@ -107,7 +107,7 @@ public static void open(final @NotNull Project project, final @NotNull PsiFile p dialog.setVisible(true); } - private void onOK() { + protected void onWriteActionOK() { if (validateFormFields()) { final OverrideLayoutInThemeGenerator overrideLayoutInThemeGenerator = new OverrideLayoutInThemeGenerator(project); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java index a0dde4de8..2a178b668 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/OverrideTemplateInThemeDialog.java @@ -110,7 +110,8 @@ public static void open(final @NotNull Project project, final @NotNull PsiFile p dialog.setVisible(true); } - private void onOK() { + protected void onWriteActionOK() { + if (validateFormFields()) { final OverrideTemplateInThemeGenerator overrideInThemeGenerator = new OverrideTemplateInThemeGenerator(project); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java index e4cdef48b..a9711b5f5 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/eavattribute/EavAttributeDialog.java @@ -248,14 +248,15 @@ protected Map> getColumnsSources() { } protected void addActionListenersForOkButton(final JButton okButton) { - okButton.addActionListener(e -> onOk()); + okButton.addActionListener(e -> onOK()); } protected void addActionListenersForOkCancel(final JButton cancelButton) { cancelButton.addActionListener(e -> onCancel()); } - protected void onOk() { + protected void onWriteActionOK() { + stopOptionsTableEditing(getOptionsTable()); if (!validateFormFields()) { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java b/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java index 326ee088f..8e7640741 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java @@ -52,6 +52,12 @@ public void update(final AnActionEvent event) { return; } + // Skip processing if the IDE is in dumb mode + if (com.intellij.openapi.project.DumbService.isDumb(project)) { + event.getPresentation().setVisible(false); + return; + } + String moduleName = null; VirtualFile psiDirectoryVirtualFile = ((PsiDirectory) psiElement).getVirtualFile(); diff --git a/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java b/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java index e9bb8b6a2..94f3fc123 100644 --- a/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java +++ b/src/main/java/com/magento/idea/magento2uct/ui/ConfigurationDialog.java @@ -129,7 +129,7 @@ public static void open(final @NotNull Project project) { * Save configuration. */ @SuppressWarnings("PMD.CyclomaticComplexity") - private void onOK() { + protected void onWriteActionOK() { modulePathError.setText(""); additionalPathError.setText(""); diff --git a/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java b/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java index f0f23ab0a..bff6e8507 100644 --- a/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java +++ b/src/main/java/com/magento/idea/magento2uct/ui/ReindexDialog.java @@ -101,7 +101,7 @@ public static void open( /** * Execute reindexing action. */ - private void onOK() { + protected void onWriteActionOK() { if (targetVersion.getSelectedItem() == null || targetIndex.getSelectedItem() == null) { return; } From 616d09c49fbbe481fd6daffef9d59f3873b9767a Mon Sep 17 00:00:00 2001 From: vitaliy Date: Fri, 21 Feb 2025 20:50:21 +0200 Subject: [PATCH 06/11] 2490: Add sponsor acknowledgments to README Acknowledgment text for sponsors was added to the README file. This change highlights support from Lucas van Staden and Ivan Chepurnyi. It enhances transparency and gratitude towards contributors. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 16723678e..20e56b464 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,9 @@ This is a PhpStorm IDE plugin for a better Magento 2 development workflow. Buy Me a Coffee +

Thank you to our sponsors—your support means everything:

+

Lucas van Staden

+

Ivan Chepurnyi

From bb394929e55806f318b01a514dccf371281340f2 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Fri, 21 Feb 2025 20:54:49 +0200 Subject: [PATCH 07/11] 2490: Enhance dialog constructors with detailed Javadoc comments Updated constructors in `NewSetupDataPatchDialog` and `NewLayoutTemplateDialog` with detailed Javadoc comments. These updates provide clarity on their purpose, parameters, and behaviors, improving code readability and maintainability. --- .../dialog/NewLayoutTemplateDialog.java | 15 ++++++++++++++- .../dialog/NewSetupDataPatchDialog.java | 11 +++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java index d7493efd6..c41f51feb 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java @@ -52,7 +52,10 @@ public class NewLayoutTemplateDialog extends AbstractDialog { private JButton buttonCancel; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, LAYOUT_NAME}) - @FieldValidation(rule = RuleRegistry.LAYOUT_NAME, message = {IdentifierRule.MESSAGE, LAYOUT_NAME}) + @FieldValidation( + rule = RuleRegistry.LAYOUT_NAME, + message = {IdentifierRule.MESSAGE, LAYOUT_NAME} + ) private JTextField layoutName; private JComboBox area; @@ -62,6 +65,13 @@ public class NewLayoutTemplateDialog extends AbstractDialog { private JLabel areaLabel; private JLabel layoutNameErrorMessage; + /** + * Constructs a new dialog for creating a layout template, initializing its components and setting + * default behaviors such as focus and button actions. + * + * @param project The current IntelliJ project associated with the dialog. + * @param directory The PsiDirectory where the new layout will be created. + */ public NewLayoutTemplateDialog(final Project project, final PsiDirectory directory) { super(); @@ -103,6 +113,9 @@ public static void open(final Project project, final PsiDirectory directory) { dialog.setVisible(true); } + /** + * Handles the action performed when the OK button is clicked in the dialog. + */ protected void onWriteActionOK() { if (validateFormFields()) { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java index 3f1cee92a..382ff406e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java @@ -48,7 +48,14 @@ public class NewSetupDataPatchDialog extends AbstractDialog { private JLabel classNameErrorMessage; /** - * Constructor + * Constructs a new instance of the NewSetupDataPatchDialog. + * This dialog facilitates the creation of a new Magento 2 Setup Data Patch, + * allowing the user to provide necessary module details and interact with a graphical user interface. + * + * @param project The current IntelliJ IDEA project context. + * @param directory The base directory where the Setup Data Patch will be created. + * @param modulePackage The package name of the target Magento 2 module. + * @param moduleName The name of the target Magento 2 module. */ public NewSetupDataPatchDialog( Project project, @@ -91,7 +98,7 @@ public void windowClosing(WindowEvent event) { } /** - * Open dialog + * Open dialog. */ public static void open( Project project, From f2239a5e66c9feba487b5381c0b78a5f8e3aec33 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Fri, 21 Feb 2025 21:00:06 +0200 Subject: [PATCH 08/11] 2490: Refactor Javadoc comments in dialog classes Removed redundant and overly verbose Javadoc comments in `NewSetupDataPatchDialog` and `NewLayoutTemplateDialog`. Simplified and clarified descriptions to enhance readability and maintain consistency. --- .../generation/dialog/NewLayoutTemplateDialog.java | 9 +++++++-- .../generation/dialog/NewSetupDataPatchDialog.java | 2 -- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java index c41f51feb..43543b78d 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java @@ -66,8 +66,7 @@ public class NewLayoutTemplateDialog extends AbstractDialog { private JLabel layoutNameErrorMessage; /** - * Constructs a new dialog for creating a layout template, initializing its components and setting - * default behaviors such as focus and button actions. + * Constructs a new dialog for creating a layout templates. * * @param project The current IntelliJ project associated with the dialog. * @param directory The PsiDirectory where the new layout will be created. @@ -106,6 +105,12 @@ public void windowClosing(WindowEvent event) { autoSelectCurrentArea(); } + /** + * Opens the New Layout Template Dialog, initializes its components. + * + * @param project The current IntelliJ project associated with the dialog. + * @param directory The PsiDirectory where the new layout will be created. + */ public static void open(final Project project, final PsiDirectory directory) { final NewLayoutTemplateDialog dialog = new NewLayoutTemplateDialog(project, directory); dialog.pack(); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java index 382ff406e..bfd312418 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java @@ -49,8 +49,6 @@ public class NewSetupDataPatchDialog extends AbstractDialog { /** * Constructs a new instance of the NewSetupDataPatchDialog. - * This dialog facilitates the creation of a new Magento 2 Setup Data Patch, - * allowing the user to provide necessary module details and interact with a graphical user interface. * * @param project The current IntelliJ IDEA project context. * @param directory The base directory where the Setup Data Patch will be created. From fdee0ec975438f74615849116accf73e00804e67 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Fri, 21 Feb 2025 22:57:43 +0200 Subject: [PATCH 09/11] 2490: Refactor and enhance dialog and module handling logic Replaced inline lambdas with method references for cleaner code, added `NOPMD` annotations to suppress redundant warnings, and improved transient field usage for serialization safety. Extracted logic for module name retrieval into a reusable method for modularity and reduced code duplication. --- .../generation/dialog/AbstractDialog.java | 31 +++++-------- .../generation/dialog/NewDataModelDialog.java | 21 +++++---- .../dialog/NewLayoutTemplateDialog.java | 9 +++- .../dialog/NewSetupDataPatchDialog.java | 45 ++++++++++--------- .../actions/groups/NewModuleFileGroup.java | 38 +++++++++++----- 5 files changed, 80 insertions(+), 64 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java index 8200b0535..eea0070c8 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java @@ -36,10 +36,13 @@ /** * All code generate dialog should extend this class. */ +@SuppressWarnings({ + "PMD.TooManyMethods" +}) public abstract class AbstractDialog extends JDialog { - protected CommonBundle bundle; - protected final ValidatorBundle validatorBundle = new ValidatorBundle(); + protected transient CommonBundle bundle; + protected final transient ValidatorBundle validatorBundle = new ValidatorBundle(); protected final List fieldsValidationsList; private final String errorTitle; private JTabbedPane tabbedPane; @@ -80,13 +83,7 @@ protected void exit() { * Executes onOK within a WriteAction context. */ protected final void executeOnOk() { - WriteAction.run(() -> { - try { - onWriteActionOK(); - } catch (Exception e) { - handleOnOkException(e); - } - }); + WriteAction.run(this::onWriteActionOK); } /** @@ -96,16 +93,6 @@ protected final void executeOnOk() { */ protected abstract void onWriteActionOK(); - /** - * Handle any exceptions that are thrown during execution of the onOK logic. - * Default implementation logs or shows the exception. - * - * @param e the exception encountered - */ - protected void handleOnOkException(Exception e) { - e.printStackTrace(); - } - /** * Hook executed when the OK button is pressed. */ @@ -118,7 +105,11 @@ protected final void onOK() { * * @return boolean */ - @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.AvoidDeeplyNestedIfStmts"}) + @SuppressWarnings({ + "PMD.CyclomaticComplexity", + "PMD.AvoidDeeplyNestedIfStmts", + "PMD.CognitiveComplexity" + }) protected boolean validateFormFields() { boolean dialogHasErrors; isValidationErrorShown = dialogHasErrors = false; diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java index 142382628..718a1337c 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java @@ -5,13 +5,9 @@ package com.magento.idea.magento2plugin.actions.generation.dialog; -import com.intellij.openapi.application.ReadAction; -import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBoxTableRenderer; import com.intellij.psi.PsiDirectory; -import com.intellij.util.RunnableCallable; -import com.intellij.util.concurrency.AppExecutorUtil; import com.magento.idea.magento2plugin.actions.generation.NewDataModelAction; import com.magento.idea.magento2plugin.actions.generation.OverrideClassByAPreferenceAction; import com.magento.idea.magento2plugin.actions.generation.data.DataModelData; @@ -55,7 +51,8 @@ import org.jetbrains.annotations.NotNull; @SuppressWarnings({ - "PMD.ExcessiveImports" + "PMD.ExcessiveImports", + "PMD.ConstructorCallsOverridableMethod" }) public class NewDataModelDialog extends AbstractDialog { @@ -67,13 +64,13 @@ public class NewDataModelDialog extends AbstractDialog { private final Project project; private final String moduleName; - private final ValidatorBundle validatorBundle; - private final CommonBundle commonBundle; + private final transient ValidatorBundle validatorBundle; + private final transient CommonBundle commonBundle; private final List properties; - private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; + private JPanel contentPanel; //NOPMD + private JButton buttonOK; //NOPMD + private JButton buttonCancel; //NOPMD private JTable propertyTable; private JButton addProperty; private JCheckBox createInterface; @@ -125,7 +122,9 @@ public void windowClosing(final WindowEvent event) { JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener(new FocusOnAFieldListener(() -> modelName.requestFocusInWindow())); + addComponentListener(new FocusOnAFieldListener(() -> { + modelName.requestFocusInWindow(); + })); } /** diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java index 43543b78d..d5afa4e7a 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java @@ -101,7 +101,7 @@ public void windowClosing(WindowEvent event) { JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener(new FocusOnAFieldListener(() -> area.requestFocusInWindow())); + addComponentListener(new FocusOnAFieldListener(this::run)); autoSelectCurrentArea(); } @@ -164,6 +164,9 @@ private void autoSelectCurrentArea() { } } + @SuppressWarnings({ + "PMD.AvoidLiteralsInIfCondition" + }) private String[] getLayoutNameParts() { final String[] layoutNameParts = layoutName.getText().trim().split("_"); String routeName = ""; @@ -189,4 +192,8 @@ private String[] getLayoutNameParts() { private String getArea() { return area.getSelectedItem().toString(); } + + private void run() { + area.requestFocusInWindow(); + } } diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java index bfd312418..1bd4d8ed4 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java @@ -27,6 +27,9 @@ import javax.swing.JTextField; import javax.swing.KeyStroke; +@SuppressWarnings({ + "PMD.ConstructorCallsOverridableMethod" +}) public class NewSetupDataPatchDialog extends AbstractDialog { private static final String CLASS_NAME = "Class Name"; @@ -36,16 +39,16 @@ public class NewSetupDataPatchDialog extends AbstractDialog { private final String moduleName; private final String modulePackage; - private JPanel contentPanel; - private JButton buttonOK; - private JButton buttonCancel; + private JPanel contentPanel; //NOPMD + private JButton buttonOK; //NOPMD + private JButton buttonCancel; //NOPMD @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, CLASS_NAME}) @FieldValidation(rule = RuleRegistry.PHP_CLASS, message = {PhpClassRule.MESSAGE, CLASS_NAME}) private JTextField className; - private JLabel classNameLabel; - private JLabel classNameErrorMessage; + private JLabel classNameLabel; //NOPMD + private JLabel classNameErrorMessage; //NOPMD /** * Constructs a new instance of the NewSetupDataPatchDialog. @@ -56,10 +59,10 @@ public class NewSetupDataPatchDialog extends AbstractDialog { * @param moduleName The name of the target Magento 2 module. */ public NewSetupDataPatchDialog( - Project project, - PsiDirectory directory, - String modulePackage, - String moduleName + final Project project, + final PsiDirectory directory, + final String modulePackage, + final String moduleName ) { super(); @@ -92,19 +95,21 @@ public void windowClosing(WindowEvent event) { JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); - addComponentListener(new FocusOnAFieldListener(() -> className.requestFocusInWindow())); + addComponentListener(new FocusOnAFieldListener(() -> { + className.requestFocusInWindow(); + })); } /** * Open dialog. */ public static void open( - Project project, - PsiDirectory directory, - String modulePackage, - String moduleName + final Project project, + final PsiDirectory directory, + final String modulePackage, + final String moduleName ) { - NewSetupDataPatchDialog dialog = new NewSetupDataPatchDialog( + final NewSetupDataPatchDialog dialog = new NewSetupDataPatchDialog( project, directory, modulePackage, @@ -127,13 +132,13 @@ protected void onWriteActionOK() { } private void generateFile() { - PsiDirectory directory = DirectoryGenerator.getInstance().findOrCreateSubdirectories( + final PsiDirectory directory = DirectoryGenerator.getInstance().findOrCreateSubdirectories( baseDir, NewSetupDataPatchAction.PATCH_DIRECTORY + "/" + NewSetupDataPatchAction.DATA_DIRECTORY ); - ModuleSetupDataPatchGenerator generator = new ModuleSetupDataPatchGenerator( + final ModuleSetupDataPatchGenerator generator = new ModuleSetupDataPatchGenerator( new ModuleSetupDataPatchData( modulePackage, moduleName, @@ -151,7 +156,7 @@ public String getClassName() { } private boolean validateFields() { - PsiDirectory patchDirectory = baseDir + final PsiDirectory patchDirectory = baseDir .findSubdirectory(NewSetupDataPatchAction.PATCH_DIRECTORY); PsiDirectory directory = null; @@ -160,8 +165,8 @@ private boolean validateFields() { } if (directory != null) { - for (PsiFile file : directory.getFiles()) { - String className = ModuleSetupDataPatchFile + for (final PsiFile file : directory.getFiles()) { + final String className = ModuleSetupDataPatchFile .resolveClassNameFromInput(getClassName()); if (file.getName().equals(className + ModuleSetupDataPatchFile.EXTENSION)) { diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java b/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java index 8e7640741..7b22f9dfe 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java @@ -19,6 +19,8 @@ import com.magento.idea.magento2plugin.actions.generation.util.IsClickedDirectoryInsideProject; import com.magento.idea.magento2plugin.project.Settings; import com.magento.idea.magento2plugin.stubs.indexes.ModuleNameIndex; +import org.jetbrains.annotations.Nullable; + import java.util.Collection; public class NewModuleFileGroup extends NonTrivialActionGroup { @@ -58,15 +60,33 @@ public void update(final AnActionEvent event) { return; } - String moduleName = null; - VirtualFile psiDirectoryVirtualFile = ((PsiDirectory) psiElement).getVirtualFile(); + final VirtualFile psiDirectoryVirtualFile = ((PsiDirectory) psiElement).getVirtualFile(); + final String moduleName = getModuleName(project, psiDirectoryVirtualFile); + if (moduleName != null) { + event.getPresentation().setVisible(true); + return; + } - for (var entry : FileBasedIndex.getInstance().getAllKeys(ModuleNameIndex.KEY, project)) { - Collection moduleVfs = FileBasedIndex.getInstance().getContainingFiles( + event.getPresentation().setVisible(false); + } + + /** + * Retrieves the module name associated with a given directory within a project. + * + * @param project the project within which the module search is performed + * @param psiDirectoryVirtualFile the virtual file representing the directory being checked + */ + private static @Nullable String getModuleName( + final Project project, + final VirtualFile psiDirectoryVirtualFile + ) { + String moduleName = null; + for (final String entry : FileBasedIndex.getInstance().getAllKeys(ModuleNameIndex.KEY, project)) { + final Collection moduleVfs = FileBasedIndex.getInstance().getContainingFiles( ModuleNameIndex.KEY, entry, GlobalSearchScope.projectScope(project) ); - for (VirtualFile moduleFile : moduleVfs) { + for (final VirtualFile moduleFile : moduleVfs) { if (moduleFile.getParent().getPath().equals(psiDirectoryVirtualFile.getPath())) { moduleName = entry; break; @@ -77,12 +97,6 @@ public void update(final AnActionEvent event) { break; } } - - if (moduleName != null) { - event.getPresentation().setVisible(true); - return; - } - - event.getPresentation().setVisible(false); + return moduleName; } } From 05c9107504d920663227c8d4eea40b042ee88ef1 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Fri, 21 Feb 2025 23:06:18 +0200 Subject: [PATCH 10/11] 2490: Refactor `NewModuleFileGroup` to optimize index usage Reused `FileBasedIndex` instance to enhance readability and performance by avoiding redundant calls. Also, fixed import order to follow code style conventions. --- .../magento2plugin/actions/groups/NewModuleFileGroup.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java b/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java index 7b22f9dfe..99fdd5f9c 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java @@ -19,9 +19,8 @@ import com.magento.idea.magento2plugin.actions.generation.util.IsClickedDirectoryInsideProject; import com.magento.idea.magento2plugin.project.Settings; import com.magento.idea.magento2plugin.stubs.indexes.ModuleNameIndex; -import org.jetbrains.annotations.Nullable; - import java.util.Collection; +import org.jetbrains.annotations.Nullable; public class NewModuleFileGroup extends NonTrivialActionGroup { @@ -81,8 +80,9 @@ public void update(final AnActionEvent event) { final VirtualFile psiDirectoryVirtualFile ) { String moduleName = null; - for (final String entry : FileBasedIndex.getInstance().getAllKeys(ModuleNameIndex.KEY, project)) { - final Collection moduleVfs = FileBasedIndex.getInstance().getContainingFiles( + final FileBasedIndex index = FileBasedIndex.getInstance(); + for (final String entry : index.getAllKeys(ModuleNameIndex.KEY, project)) { + final Collection moduleVfs = index.getContainingFiles( ModuleNameIndex.KEY, entry, GlobalSearchScope.projectScope(project) ); From 7c5a4cc435f43b0964fbfbdde6c63e448679dca1 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Fri, 21 Feb 2025 23:13:54 +0200 Subject: [PATCH 11/11] 2490: Refactor to improve code clarity and adhere to standards Added //NOPMD comments to suppress PMD warnings on JLabel fields. Updated method signatures to use final for consistency and improved readability. --- .../generation/dialog/NewLayoutTemplateDialog.java | 8 ++++---- .../generation/dialog/NewSetupDataPatchDialog.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java index d5afa4e7a..a8c72c375 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.java @@ -61,9 +61,9 @@ public class NewLayoutTemplateDialog extends AbstractDialog { private JComboBox area; // labels - private JLabel layoutNameLabel; - private JLabel areaLabel; - private JLabel layoutNameErrorMessage; + private JLabel layoutNameLabel; //NOPMD + private JLabel areaLabel; //NOPMD + private JLabel layoutNameErrorMessage; //NOPMD /** * Constructs a new dialog for creating a layout templates. @@ -90,7 +90,7 @@ public NewLayoutTemplateDialog(final Project project, final PsiDirectory directo setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override - public void windowClosing(WindowEvent event) { + public void windowClosing(final WindowEvent event) { onCancel(); } }); diff --git a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java index 1bd4d8ed4..4c751cc7e 100644 --- a/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java +++ b/src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewSetupDataPatchDialog.java @@ -83,7 +83,7 @@ public NewSetupDataPatchDialog( setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override - public void windowClosing(WindowEvent event) { + public void windowClosing(final WindowEvent event) { onCancel(); } });