Skip to content

Commit e3b6024

Browse files
Merge branch '4.0.0-develop' of github.com:magento/magento2-phpstorm-plugin into entity-web-api-generation
2 parents 5d3f555 + 7f9abe1 commit e3b6024

File tree

5 files changed

+115
-42
lines changed

5 files changed

+115
-42
lines changed

resources/META-INF/pluginIcon.svg

Lines changed: 41 additions & 1 deletion
Loading

resources/META-INF/pluginIcon_dark.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/com/magento/idea/magento2plugin/actions/CopyMagentoPath.java

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,47 @@
1515
import com.intellij.psi.PsiFile;
1616
import com.intellij.psi.PsiManager;
1717
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
18+
import java.util.Arrays;
19+
import java.util.List;
1820
import org.jetbrains.annotations.NotNull;
1921
import org.jetbrains.annotations.Nullable;
2022

2123
public class CopyMagentoPath extends CopyPathProvider {
22-
public static final String PHTML = "phtml";
23-
public static final String PHTML_SEPARATOR = "::";
24+
public static final String PHTML_EXTENSION = "phtml";
25+
public static final String JS_EXTENSION = "js";
26+
public static final String CSS_EXTENSION = "css";
27+
private final List<String> acceptedTypes
28+
= Arrays.asList(PHTML_EXTENSION, JS_EXTENSION, CSS_EXTENSION);
29+
public static final String SEPARATOR = "::";
2430
private int index;
31+
2532
private final String[] templatePaths = {
2633
"view/frontend/templates/",
2734
"view/adminhtml/templates/",
2835
"view/base/templates/",
2936
"templates/"
3037
};
3138

39+
private final String[] webPaths = {
40+
"view/frontend/web/",
41+
"view/adminhtml/web/",
42+
"view/base/web/",
43+
"web/"
44+
};
45+
3246
@Override
3347
public void update(@NotNull final AnActionEvent event) {
3448
final VirtualFile virtualFile = event.getData(PlatformDataKeys.VIRTUAL_FILE);
35-
if (virtualFile != null && virtualFile.isDirectory()
36-
|| virtualFile != null && !PHTML.equals(virtualFile.getExtension())) {
49+
if (isNotValidFile(virtualFile)) {
3750
event.getPresentation().setVisible(false);
3851
}
3952
}
4053

54+
private boolean isNotValidFile(final VirtualFile virtualFile) {
55+
return virtualFile != null && virtualFile.isDirectory()
56+
|| virtualFile != null && !acceptedTypes.contains(virtualFile.getExtension());
57+
}
58+
4159
@Nullable
4260
@Override
4361
public String getPathToElement(
@@ -59,27 +77,30 @@ public String getPathToElement(
5977
return null;
6078
}
6179
final StringBuilder fullPath = new StringBuilder(virtualFile.getPath());
62-
final StringBuilder magentoPath
63-
= new StringBuilder(moduleName);
64-
String path = fullPath.toString();
6580

66-
if (PHTML.equals(virtualFile.getExtension())) {
67-
index = -1;
68-
final int endIndex = getIndexOf(fullPath, templatePaths[++index]);
69-
final int offset = templatePaths[index].length();
81+
index = -1;
82+
String[] paths;
7083

71-
fullPath.replace(0, endIndex + offset, "");
72-
magentoPath.append(PHTML_SEPARATOR);
73-
magentoPath.append(fullPath);
74-
path = magentoPath.toString();
84+
if (PHTML_EXTENSION.equals(virtualFile.getExtension())) {
85+
paths = templatePaths;
86+
} else if (JS_EXTENSION.equals(virtualFile.getExtension())
87+
|| CSS_EXTENSION.equals(virtualFile.getExtension())) {
88+
paths = webPaths;
89+
} else {
90+
return fullPath.toString();
7591
}
7692

77-
return path;
93+
final int endIndex = getIndexOf(paths, fullPath, paths[++index]);
94+
final int offset = paths[index].length();
95+
96+
fullPath.replace(0, endIndex + offset, "");
97+
98+
return moduleName + SEPARATOR + fullPath;
7899
}
79100

80-
private int getIndexOf(final StringBuilder fullPath, final String path) {
101+
private int getIndexOf(final String[] paths, final StringBuilder fullPath, final String path) {
81102
return fullPath.lastIndexOf(path) == -1
82-
? getIndexOf(fullPath, templatePaths[++index])
103+
? getIndexOf(paths, fullPath, paths[++index])
83104
: fullPath.lastIndexOf(path);
84105
}
85106
}

src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public void visitFile(final PsiFile file) {
100100
}
101101

102102
final String observerName = observerNameAttribute.getValue();
103+
if (observerName == null) {
104+
continue;
105+
}
106+
103107
final String observerKey = eventNameAttributeValue.concat("_")
104108
.concat(observerName);
105109
if (targetObserversHash.containsKey(observerKey)) {
@@ -124,22 +128,21 @@ public void visitFile(final PsiFile file) {
124128
if (observerDisabledAttribute != null
125129
&& observerDisabledAttribute.getValue() != null
126130
&& observerDisabledAttribute.getValue().equals("true")
127-
&& modulesWithSameObserverName.isEmpty()
128-
) {
129-
problemsHolder.registerProblem(
130-
observerNameAttribute.getValueElement(),
131-
inspectionBundle.message(
132-
"inspection.observer.disabledObserverDoesNotExist"
133-
),
134-
errorSeverity
135-
);
136-
}
137-
138-
if (observerDisabledAttribute != null
139-
&& observerDisabledAttribute.getValue() != null
140-
&& observerDisabledAttribute.getValue().equals("true")
131+
&& !observerName.isEmpty()
141132
) {
133+
@Nullable final XmlAttributeValue valueElement
134+
= observerNameAttribute.getValueElement();
135+
if (modulesWithSameObserverName.isEmpty() && valueElement != null) {
136+
problemsHolder.registerProblem(
137+
valueElement,
138+
inspectionBundle.message(
139+
"inspection.observer.disabledObserverDoesNotExist"
140+
),
141+
errorSeverity
142+
);
143+
} else {
142144
continue;
145+
}
143146
}
144147

145148
for (final HashMap<String, String> moduleEntry:

src/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspection.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public void visitFile(final PsiFile file) {
9393
}
9494

9595
final String pluginTypeName = pluginTypeNameAttribute.getValue();
96+
if (pluginTypeName == null) {
97+
continue;
98+
}
99+
96100
final String pluginTypeKey = pluginNameAttributeValue.concat(
97101
Package.vendorModuleNameSeparator
98102
).concat(pluginTypeName);
@@ -118,15 +122,21 @@ public void visitFile(final PsiFile file) {
118122
if (pluginTypeDisabledAttribute != null
119123
&& pluginTypeDisabledAttribute.getValue() != null
120124
&& pluginTypeDisabledAttribute.getValue().equals("true")
121-
&& modulesWithSamePluginName.isEmpty()
125+
&& !pluginTypeName.isEmpty()
122126
) {
123-
problemsHolder.registerProblem(
124-
pluginTypeNameAttribute.getValueElement(),
125-
inspectionBundle.message(
126-
"inspection.plugin.disabledPluginDoesNotExist"
127-
),
128-
errorSeverity
129-
);
127+
@Nullable final XmlAttributeValue valueElement
128+
= pluginTypeNameAttribute.getValueElement();
129+
if (modulesWithSamePluginName.isEmpty() && valueElement != null) {
130+
problemsHolder.registerProblem(
131+
valueElement,
132+
inspectionBundle.message(
133+
"inspection.plugin.disabledPluginDoesNotExist"
134+
),
135+
errorSeverity
136+
);
137+
} else {
138+
continue;
139+
}
130140
}
131141

132142
for (final Pair<String, String> moduleEntry: modulesWithSamePluginName) {

0 commit comments

Comments
 (0)