Skip to content

Commit 28b9902

Browse files
Merge branch '4.3.1-develop' of github.com:magento/magento2-phpstorm-plugin into pre-release-4.4.0
2 parents 0df88ca + 9da9818 commit 28b9902

File tree

10 files changed

+198
-89
lines changed

10 files changed

+198
-89
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0).
2525
- Fixed argument for @NotNull parameter 'project' must not be null in the OverrideClassByAPreferenceAction [#1116](https://github.com/magento/magento2-phpstorm-plugin/pull/1116)
2626
- Fixed New layout action doesn't accept valid layout names [#1114](https://github.com/magento/magento2-phpstorm-plugin/pull/1114)
2727

28+
## 4.3.1
29+
30+
### Changed
31+
32+
- Added raw plugin verifier configuration in [#1065](https://github.com/magento/magento2-phpstorm-plugin/pull/1065)
33+
34+
### Fixed
35+
36+
- Fixed bug with the file separator on Windows OS (while saving plugin settings) in [#1062](https://github.com/magento/magento2-phpstorm-plugin/pull/1062)
37+
- Fixed bug with wrong text range for FilePathReferenceProvider.getReferencesByElement in [#1063](https://github.com/magento/magento2-phpstorm-plugin/pull/1063)
38+
- Fixed module files action group is accessible from the theme context in [#1064](https://github.com/magento/magento2-phpstorm-plugin/pull/1064)
39+
- Fixed bug with directory index is already disposed for Project in AllFilesExceptTestsScope.contains in [#1080](https://github.com/magento/magento2-phpstorm-plugin/pull/1080)
40+
- Fixed bug with DumbService cannot be created because container is already disposed in MagentoComponentManager.getComponents in [#1081](https://github.com/magento/magento2-phpstorm-plugin/pull/1081)
41+
2842
## 4.3.0
2943

3044
### Added

src/com/magento/idea/magento2plugin/actions/context/AbstractContextAction.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import com.intellij.psi.PsiFile;
2121
import com.magento.idea.magento2plugin.MagentoIcons;
2222
import com.magento.idea.magento2plugin.magento.files.ModuleFileInterface;
23+
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
2324
import com.magento.idea.magento2plugin.magento.packages.Package;
25+
import com.magento.idea.magento2plugin.project.Settings;
2426
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
2527
import org.jetbrains.annotations.NotNull;
2628
import org.jetbrains.annotations.Nullable;
@@ -50,13 +52,14 @@ public AbstractContextAction(
5052
}
5153

5254
@Override
55+
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
5356
public void update(final @NotNull AnActionEvent event) {
5457
event.getPresentation().setEnabled(false);
5558
event.getPresentation().setVisible(false);
5659

5760
final Project project = event.getProject();
5861

59-
if (project == null) {
62+
if (project == null || !Settings.isEnabled(project)) {
6063
return;
6164
}
6265
final DataContext context = event.getDataContext();
@@ -86,6 +89,12 @@ public void update(final @NotNull AnActionEvent event) {
8689
|| !isVisible(moduleData, targetDirectory, targetFile)) {
8790
return;
8891
}
92+
93+
if (moduleData.getType().equals(ComponentType.module)
94+
&& !GetMagentoModuleUtil.isEditableModule(moduleData)) {
95+
return;
96+
}
97+
8998
customDataContext = SimpleDataContext
9099
.builder()
91100
.add(

src/com/magento/idea/magento2plugin/actions/groups/NewModuleFileGroup.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.magento.idea.magento2plugin.actions.generation.util.IsClickedDirectoryInsideProject;
1717
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
1818
import com.magento.idea.magento2plugin.project.Settings;
19+
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil;
1920
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
2021
import javax.swing.Icon;
2122
import org.jetbrains.annotations.NotNull;
@@ -62,7 +63,8 @@ public void update(final AnActionEvent event) {
6263
final PsiDirectory moduleDirectory = new ModuleIndex(project)
6364
.getModuleDirectoryByModuleName(moduleName);
6465

65-
if (moduleDirectory != null) {
66+
if (moduleDirectory != null
67+
&& GetMagentoModuleUtil.isDirectoryInEditableModule(moduleDirectory)) {
6668
event.getPresentation().setVisible(true);
6769
return;
6870
}

src/com/magento/idea/magento2plugin/lang/psi/search/AllFilesExceptTestsScope.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,14 @@
1616
public final class AllFilesExceptTestsScope extends GlobalSearchScope {
1717

1818
public static final String SCOPE_NAME = "All Files Except Tests";
19-
private static AllFilesExceptTestsScope instance;
2019
private final Project project;
2120

22-
/**
23-
* Get search scope instance.
24-
*
25-
* @param project Project
26-
*
27-
* @return AllFilesExceptTestsScope
28-
*/
29-
@SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
30-
public static synchronized AllFilesExceptTestsScope getInstance(
31-
final @Nullable Project project
32-
) {
33-
if (instance == null) {
34-
instance = new AllFilesExceptTestsScope(project);
35-
}
36-
37-
return instance;
38-
}
39-
4021
/**
4122
* Magento search scope constructor.
4223
*
4324
* @param project Project
4425
*/
45-
private AllFilesExceptTestsScope(final @Nullable Project project) {
26+
public AllFilesExceptTestsScope(final @Nullable Project project) {
4627
super(project);
4728
this.project = project;
4829
}

src/com/magento/idea/magento2plugin/lang/psi/search/MagentoSearchScopesProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ public class MagentoSearchScopesProvider implements SearchScopeProvider {
3232
return Collections.emptyList();
3333
}
3434

35-
return Collections.singletonList(AllFilesExceptTestsScope.getInstance(project));
35+
return Collections.singletonList(new AllFilesExceptTestsScope(project));
3636
}
3737
}

src/com/magento/idea/magento2plugin/magento/packages/MagentoComponentManager.java

Lines changed: 99 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
/**
1+
/*
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.magento.packages;
67

78
import com.intellij.json.psi.JsonFile;
89
import com.intellij.json.psi.JsonObject;
10+
import com.intellij.openapi.components.Service;
911
import com.intellij.openapi.project.DumbService;
1012
import com.intellij.openapi.project.Project;
1113
import com.intellij.openapi.vfs.VirtualFile;
@@ -18,40 +20,48 @@
1820
import com.intellij.psi.xml.XmlTag;
1921
import com.intellij.util.indexing.FileBasedIndex;
2022
import com.magento.idea.magento2plugin.stubs.indexes.ModulePackageIndex;
21-
import org.jetbrains.annotations.NotNull;
22-
import org.jetbrains.annotations.Nullable;
2323
import java.util.ArrayList;
2424
import java.util.Collection;
2525
import java.util.HashMap;
2626
import java.util.Map;
27+
import org.jetbrains.annotations.NotNull;
28+
import org.jetbrains.annotations.Nullable;
29+
30+
@Service
31+
public final class MagentoComponentManager {
2732

28-
public class MagentoComponentManager {
2933
private Map<String, MagentoComponent> components = new HashMap<>();
3034
private long cacheStartTime;
31-
private static final int CACHE_LIFE_TIME = 20000;
32-
private static MagentoComponentManager magentoComponentManager;
33-
private Project project;
35+
private static final int CACHE_LIFE_TIME = 20000;//NOPMD
36+
private final Project project;
3437

35-
private MagentoComponentManager(Project project){
38+
public MagentoComponentManager(final Project project) {
3639
this.project = project;
3740
}
3841

39-
public static MagentoComponentManager getInstance(@NotNull Project project) {
40-
if (magentoComponentManager == null) {
41-
magentoComponentManager = new MagentoComponentManager(project);
42-
}
43-
return magentoComponentManager;
42+
public static MagentoComponentManager getInstance(final @NotNull Project project) {
43+
return project.getService(MagentoComponentManager.class);
4444
}
4545

4646
public Collection<MagentoComponent> getAllComponents() {
4747
return getComponents().values();
4848
}
4949

50+
/**
51+
* Get all components of the specified type.
52+
*
53+
* @param type Class
54+
*
55+
* @return Collection
56+
*/
5057
@SuppressWarnings("unchecked")
51-
public <T extends MagentoComponent> Collection<T> getAllComponentsOfType(@NotNull Class<T> type) {
52-
Collection<T> result = new ArrayList<>();
53-
Map<String, MagentoComponent> components = getComponents();
54-
for (String key: components.keySet()) {
58+
public <T extends MagentoComponent> Collection<T> getAllComponentsOfType(
59+
final @NotNull Class<T> type
60+
) {
61+
final Collection<T> result = new ArrayList<>();
62+
final Map<String, MagentoComponent> components = getComponents();
63+
64+
for (final String key: components.keySet()) {
5565
if (type.isInstance(components.get(key))) {
5666
result.add((T)components.get(key));
5767
}
@@ -60,8 +70,9 @@ public <T extends MagentoComponent> Collection<T> getAllComponentsOfType(@NotNul
6070
return result;
6171
}
6272

63-
synchronized private Map<String, MagentoComponent> getComponents() {
64-
if (DumbService.getInstance(project).isDumb() || project.isDisposed()) {
73+
@SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
74+
private synchronized Map<String, MagentoComponent> getComponents() {
75+
if (project.isDisposed() || DumbService.getInstance(project).isDumb()) {
6576
return new HashMap<>();
6677
}
6778

@@ -74,9 +85,16 @@ synchronized private Map<String, MagentoComponent> getComponents() {
7485
return components;
7586
}
7687

88+
/**
89+
* Get component for the specified file.
90+
*
91+
* @param psiFile PsiFile
92+
*
93+
* @return MagentoComponent
94+
*/
7795
@Nullable
78-
public MagentoComponent getComponentForFile(@NotNull PsiFile psiFile) {
79-
for (MagentoComponent magentoComponent: this.getAllComponents()) {
96+
public MagentoComponent getComponentForFile(final @NotNull PsiFile psiFile) {
97+
for (final MagentoComponent magentoComponent: this.getAllComponents()) {
8098
if (magentoComponent.isFileInContext(psiFile)) {
8199
return magentoComponent;
82100
}
@@ -85,10 +103,21 @@ public MagentoComponent getComponentForFile(@NotNull PsiFile psiFile) {
85103
return null;
86104
}
87105

106+
/**
107+
* Get component of type for the specified file.
108+
*
109+
* @param psiFile PsiFile
110+
* @param type Class
111+
*
112+
* @return T
113+
*/
88114
@Nullable
89115
@SuppressWarnings("unchecked")
90-
public <T extends MagentoComponent> T getComponentOfTypeForFile(@NotNull PsiFile psiFile, @NotNull Class<T> type) {
91-
for (MagentoComponent magentoComponent: this.getAllComponents()) {
116+
public <T extends MagentoComponent> T getComponentOfTypeForFile(
117+
final @NotNull PsiFile psiFile,
118+
final @NotNull Class<T> type
119+
) {
120+
for (final MagentoComponent magentoComponent: this.getAllComponents()) {
92121
if (type.isInstance(magentoComponent) && magentoComponent.isFileInContext(psiFile)) {
93122
return (T)magentoComponent;
94123
}
@@ -97,72 +126,97 @@ public <T extends MagentoComponent> T getComponentOfTypeForFile(@NotNull PsiFile
97126
return null;
98127
}
99128

100-
synchronized public void flushModules() {
129+
@SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
130+
public synchronized void flushModules() {
101131
components = new HashMap<>();
102132
}
103133

134+
@SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops", "PMD.AvoidDeeplyNestedIfStmts"})
104135
private void loadModules() {
105-
Collection<String> packages = FileBasedIndex.getInstance().getAllKeys(ModulePackageIndex.KEY, this.project);
106-
PsiManager psiManager = PsiManager.getInstance(this.project);
107-
for (String packageName: packages) {
136+
final Collection<String> packages = FileBasedIndex
137+
.getInstance()
138+
.getAllKeys(ModulePackageIndex.KEY, this.project);
139+
final PsiManager psiManager = PsiManager.getInstance(this.project);
140+
141+
for (final String packageName: packages) {
108142
if (components.containsKey(packageName)) {
109143
continue;
110144
}
111145

112-
Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance()
113-
.getContainingFiles(ModulePackageIndex.KEY, packageName, GlobalSearchScope.allScope(this.project));
146+
final Collection<VirtualFile> containingFiles = FileBasedIndex
147+
.getInstance()
148+
.getContainingFiles(
149+
ModulePackageIndex.KEY,
150+
packageName,
151+
GlobalSearchScope.allScope(this.project)
152+
);
114153

115-
if (containingFiles.size() > 0) {
116-
VirtualFile configurationFile = containingFiles.iterator().next();
154+
if (!containingFiles.isEmpty()) {
155+
final VirtualFile configurationFile = containingFiles.iterator().next();
156+
final PsiFile psiFile = psiManager.findFile(configurationFile);
117157

118-
PsiFile psiFile = psiManager.findFile(configurationFile);
119-
if (psiFile != null && psiFile instanceof JsonFile) {
120-
JsonObject jsonObject = PsiTreeUtil.getChildOfType((JsonFile) psiFile, JsonObject.class);
158+
if (psiFile instanceof JsonFile) {
159+
final JsonObject jsonObject = PsiTreeUtil
160+
.getChildOfType((JsonFile) psiFile, JsonObject.class);
121161
if (jsonObject == null) {
122162
continue;
123163
}
124164

125165
MagentoComponent magentoComponent;
126-
ComposerPackageModel composerPackageModel = new ComposerPackageModelImpl(jsonObject);
166+
final ComposerPackageModel composerPackageModel = new ComposerPackageModelImpl(
167+
jsonObject
168+
);
169+
127170
if ("magento2-module".equals(composerPackageModel.getType())) {
128-
magentoComponent = new MagentoModuleImpl(new ComposerPackageModelImpl(jsonObject), psiFile.getContainingDirectory());
171+
magentoComponent = new MagentoModuleImpl(
172+
new ComposerPackageModelImpl(jsonObject),
173+
psiFile.getContainingDirectory()
174+
);
129175
} else {
130-
magentoComponent = new MagentoComponentImp(new ComposerPackageModelImpl(jsonObject), psiFile.getContainingDirectory());
176+
magentoComponent = new MagentoComponentImp(
177+
new ComposerPackageModelImpl(jsonObject),
178+
psiFile.getContainingDirectory()
179+
);
131180
}
132181

133182
components.put(
134-
packageName,
135-
magentoComponent
183+
packageName,
184+
magentoComponent
136185
);
137186
}
138187
}
139188
}
140189
}
141190
}
142191

192+
@SuppressWarnings("checkstyle:OneTopLevelClass")
143193
class MagentoModuleImpl extends MagentoComponentImp implements MagentoModule {
144194
private static final String DEFAULT_MODULE_NAME = "Undefined module";
145195
private static final String CONFIGURATION_PATH = "etc";
146196
private String moduleName;
147197

148-
public MagentoModuleImpl(@NotNull ComposerPackageModel composerPackageModel, @NotNull PsiDirectory directory) {
198+
public MagentoModuleImpl(
199+
final @NotNull ComposerPackageModel composerPackageModel,
200+
final @NotNull PsiDirectory directory
201+
) {
149202
super(composerPackageModel, directory);
150203
}
151204

205+
@SuppressWarnings({"PMD.AvoidDeeplyNestedIfStmts"})
152206
@Override
153207
public String getMagentoName() {
154208
if (moduleName != null) {
155209
return moduleName;
156210
}
157211

158-
PsiDirectory configurationDir = directory.findSubdirectory(CONFIGURATION_PATH);
212+
final PsiDirectory configurationDir = directory.findSubdirectory(CONFIGURATION_PATH);
159213
if (configurationDir != null) {
160-
PsiFile configurationFile = configurationDir.findFile("module.xml");
214+
final PsiFile configurationFile = configurationDir.findFile("module.xml");
161215

162-
if (configurationFile != null && configurationFile instanceof XmlFile) {
163-
XmlTag rootTag = ((XmlFile) configurationFile).getRootTag();
216+
if (configurationFile instanceof XmlFile) {
217+
final XmlTag rootTag = ((XmlFile) configurationFile).getRootTag();
164218
if (rootTag != null) {
165-
XmlTag module = rootTag.findFirstSubTag("module");
219+
final XmlTag module = rootTag.findFirstSubTag("module");
166220
if (module != null && module.getAttributeValue("name") != null) {
167221
moduleName = module.getAttributeValue("name");
168222
return moduleName;

0 commit comments

Comments
 (0)