Skip to content

Commit 5183af0

Browse files
authored
Merge pull request #2500 from vitaliyboykocontributor/1658-Cannot-invoke-com.intellij.psi.PsiDirectory.getName()-
1658: Improve null safety and refactor UI interaction handling.
2 parents 4250faa + 1282dda commit 5183af0

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0).
1212
- "Copy Path/Reference" does not show the preview value [#2497](https://github.com/magento/magento2-phpstorm-plugin/pull/2497)
1313
- Must not start write action from within read action in the other thread [#2498](https://github.com/magento/magento2-phpstorm-plugin/pull/2498)
1414
- URN map generation during indexing [#2499](https://github.com/magento/magento2-phpstorm-plugin/pull/2499)
15+
- Cannot invoke "com.intellij.psi.PsiDirectory.getName() [#2500](https://github.com/magento/magento2-phpstorm-plugin/pull/2500)
1516

1617
## 2025.0.0
1718

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
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 {
24-
2525
/**
2626
* OverrideTemplateInThemeGenerator constructor.
2727
*
@@ -41,10 +41,13 @@ public void execute(final PsiFile baseFile, final String themeName) {
4141

4242
final GetMagentoModuleUtil.MagentoModuleData moduleData =
4343
GetMagentoModuleUtil.getByContext(baseFile.getContainingDirectory(), project);
44-
List<String> pathComponents;
44+
List<String> pathComponents; //NOPMD
4545

4646
if (moduleData == null) {
47-
if (baseFile.getVirtualFile().getExtension().equals(OverridableFileType.JS.getType())) {
47+
if (Objects.equals(
48+
baseFile.getVirtualFile().getExtension(),
49+
OverridableFileType.JS.getType())
50+
) {
4851
pathComponents = getLibPathComponets(baseFile);
4952
} else {
5053
return;
@@ -75,12 +78,21 @@ public void execute(final PsiFile baseFile, final String themeName) {
7578
directory = getTargetDirectory(directory, pathComponents);
7679

7780
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);
81+
final PsiDirectory finalDirectory1 = directory;
82+
ApplicationManager.getApplication().invokeLater(() -> {
83+
JBPopupFactory.getInstance()
84+
.createMessage(
85+
validatorBundle.message(
86+
"validator.file.alreadyExists",
87+
baseFile.getName()
88+
)
89+
).showCenteredInCurrentWindow(project);
90+
ApplicationManager.getApplication().invokeLater(() -> {
91+
Objects.requireNonNull(
92+
finalDirectory1.findFile(baseFile.getName())
93+
).navigate(true);
94+
});
95+
});
8496
return;
8597
}
8698

0 commit comments

Comments
 (0)