Skip to content

Commit 5b91b53

Browse files
committedFeb 23, 2025
1658: Improve null safety and refactor UI interaction handling.
Replaced direct string equality checks with `Objects.equals` for better null safety. Refactored popup and navigation logic using `invokeLater` to improve UI interaction handling and avoid potential threading issues. Added PMD suppression for clarity without affecting standards compliance.
1 parent 4250faa commit 5b91b53

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed
 

‎src/main/java/com/magento/idea/magento2plugin/actions/generation/generator/OverrideTemplateInThemeGenerator.java

+13-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.magento.idea.magento2plugin.util.magento.GetComponentNameByDirectoryUtil;
2020
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
2121
import java.util.List;
22+
import java.util.Objects;
2223

2324
public class OverrideTemplateInThemeGenerator extends OverrideInThemeGenerator {
2425

@@ -41,10 +42,10 @@ public void execute(final PsiFile baseFile, final String themeName) {
4142

4243
final GetMagentoModuleUtil.MagentoModuleData moduleData =
4344
GetMagentoModuleUtil.getByContext(baseFile.getContainingDirectory(), project);
44-
List<String> pathComponents;
45+
List<String> pathComponents; //NOPMD
4546

4647
if (moduleData == null) {
47-
if (baseFile.getVirtualFile().getExtension().equals(OverridableFileType.JS.getType())) {
48+
if (Objects.equals(baseFile.getVirtualFile().getExtension(), OverridableFileType.JS.getType())) {
4849
pathComponents = getLibPathComponets(baseFile);
4950
} else {
5051
return;
@@ -75,15 +76,19 @@ public void execute(final PsiFile baseFile, final String themeName) {
7576
directory = getTargetDirectory(directory, pathComponents);
7677

7778
if (directory.findFile(baseFile.getName()) != null) {
78-
JBPopupFactory.getInstance()
79-
.createMessage(
80-
validatorBundle.message("validator.file.alreadyExists", baseFile.getName())
81-
)
82-
.showCenteredInCurrentWindow(project);
83-
directory.findFile(baseFile.getName()).navigate(true);
79+
PsiDirectory finalDirectory1 = directory;
80+
ApplicationManager.getApplication().invokeLater(() -> {
81+
JBPopupFactory.getInstance()
82+
.createMessage(validatorBundle.message("validator.file.alreadyExists", baseFile.getName()))
83+
.showCenteredInCurrentWindow(project);
84+
ApplicationManager.getApplication().invokeLater(() -> {
85+
Objects.requireNonNull(finalDirectory1.findFile(baseFile.getName())).navigate(true);
86+
});
87+
});
8488
return;
8589
}
8690

91+
8792
final PsiDirectory finalDirectory = directory;
8893
ApplicationManager.getApplication().runWriteAction(() -> {
8994
finalDirectory.copyFileFrom(baseFile.getName(), baseFile);

0 commit comments

Comments
 (0)