Skip to content

Commit cd06a38

Browse files
Merge branch '4.2.2-develop' of github.com:magento/magento2-phpstorm-plugin into 858-error-correction-in-case-entered-fields-is-zero
2 parents a00d39a + b52643e commit cd06a38

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,19 @@ private void createUIComponents() {
263263
* @return String
264264
*/
265265
private String suggestCronjobName(final String cronjobClassname) {
266+
if (moduleName == null) {
267+
return "";
268+
}
269+
266270
if (cronjobClassname == null || cronjobClassname.isEmpty()) {
267-
return this.moduleName.toLowerCase(new java.util.Locale("en","EN"));
271+
return moduleName.toLowerCase(new java.util.Locale("en","EN"));
268272
}
269273

270274
final String cronjobClassnameToSnakeCase = this.camelCaseToSnakeCase.convert(
271275
cronjobClassname
272276
);
273277

274-
return this.moduleName.toLowerCase(new java.util.Locale("en","EN"))
278+
return moduleName.toLowerCase(new java.util.Locale("en","EN"))
275279
+ "_"
276280
+ cronjobClassnameToSnakeCase;
277281
}

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
import java.util.List;
1010

1111
public enum MessageQueueConnections {
12+
1213
DB("db"),
13-
AMPQ("ampq");
14+
AMPQ("amqp");
1415

1516
private final String type;
1617

@@ -32,16 +33,6 @@ public String getType() {
3233
return type;
3334
}
3435

35-
/**
36-
* Get connection type by name.
37-
*
38-
* @param typeName type name
39-
* @return Request Interface
40-
*/
41-
public static String getConnectionTypeByName(final String typeName) {
42-
return MessageQueueConnections.valueOf(typeName).getType();
43-
}
44-
4536
/**
4637
* Get list of connection types.
4738
*
@@ -51,7 +42,7 @@ public static List<String> getList() {
5142
final List<String> typeList = new ArrayList<>();
5243

5344
for (final MessageQueueConnections type: MessageQueueConnections.values()) {
54-
typeList.add(getConnectionTypeByName(type.name()));
45+
typeList.add(type.getType());
5546
}
5647

5748
return typeList;

src/com/magento/idea/magento2plugin/util/magento/GetModuleNameByDirectoryUtil.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.magento.idea.magento2plugin.util.RegExUtil;
1717
import java.util.regex.Matcher;
1818
import java.util.regex.Pattern;
19+
import org.jetbrains.annotations.NotNull;
1920
import org.jetbrains.annotations.Nullable;
2021

2122
public final class GetModuleNameByDirectoryUtil {
@@ -27,18 +28,21 @@ private GetModuleNameByDirectoryUtil() {}
2728
*
2829
* @param psiDirectory PsiDirectory
2930
* @param project Project
31+
*
3032
* @return String
3133
*/
32-
public static String execute(
33-
final PsiDirectory psiDirectory,
34-
final Project project
34+
public static @Nullable String execute(
35+
final @NotNull PsiDirectory psiDirectory,
36+
final @NotNull Project project
3537
) {
3638
// Check if directory is theme directory and return module name from directory path if yes
3739
final String path = psiDirectory.getVirtualFile().getPath();
3840
final Pattern pattern = Pattern.compile(RegExUtil.CustomTheme.MODULE_NAME);
3941
final Matcher matcher = pattern.matcher(path);
42+
4043
while (matcher.find()) {
4144
final String moduleNamePath = matcher.group(0);
45+
4246
if (!moduleNamePath.isEmpty()) {
4347
return moduleNamePath.split("/")[5];
4448
}
@@ -48,33 +52,39 @@ public static String execute(
4852
psiDirectory,
4953
project
5054
);
55+
5156
if (registrationPhp == null) {
5257
return null;
5358
}
5459
final PsiElement[] childElements = registrationPhp.getChildren();
60+
5561
if (childElements.length == 0) {
5662
return null;
5763
}
64+
5865
return getModuleName(childElements);
5966
}
6067

61-
private static MethodReference[] parseRegistrationPhpElements(//NOPMD
68+
private static MethodReference[] parseRegistrationPhpElements(
6269
final PsiElement... elements
6370
) {
64-
for (final PsiElement element: elements) {
71+
for (final PsiElement element : elements) {
6572
MethodReference[] methods = PsiTreeUtil.getChildrenOfType(
6673
element,
6774
MethodReference.class
6875
);
76+
6977
if (methods == null) {
7078
final PsiElement[] children = element.getChildren();
7179
methods = parseRegistrationPhpElements(children);
7280
}
73-
if (methods != null) {
81+
82+
if (methods.length > 0) {
7483
return methods;
7584
}
7685
}
77-
return null;
86+
87+
return new MethodReference[0];
7888
}
7989

8090
private static PhpFile getRegistrationPhpRecursively(
@@ -99,25 +109,30 @@ private static PhpFile getRegistrationPhpRecursively(
99109

100110
private static String getModuleName(final PsiElement... childElements) {
101111
final MethodReference[] methods = parseRegistrationPhpElements(childElements);
102-
if (methods == null) {
112+
113+
if (methods.length == 0) {
103114
return null;
104115
}
116+
105117
for (final MethodReference method: methods) {
106-
if (!method.getName().equals(RegistrationPhp.REGISTER_METHOD_NAME)) {
118+
if (!RegistrationPhp.REGISTER_METHOD_NAME.equals(method.getName())) {
107119
continue;
108120
}
109121
final PsiElement[] parameters = method.getParameters();
122+
110123
for (final PsiElement parameter: parameters) {
111124
if (!(parameter instanceof StringLiteralExpression)) {
112125
continue;
113126
}
114127
final String moduleName = ((StringLiteralExpression) parameter)
115128
.getContents();
129+
116130
if (moduleName.matches(RegExUtil.Magento.MODULE_NAME)) {
117131
return moduleName;
118132
}
119133
}
120134
}
135+
121136
return null;
122137
}
123138

@@ -131,11 +146,13 @@ private static PhpFile getModuleRegistrationPhpFile(
131146
continue;
132147
}
133148
final String filename = ((PhpFile) containingFile).getName();
134-
if (filename.equals(RegistrationPhp.FILE_NAME)) {
149+
150+
if (RegistrationPhp.FILE_NAME.equals(filename)) {
135151
return (PhpFile) containingFile;
136152
}
137153
}
138154
}
155+
139156
return null;
140157
}
141158
}

src/com/magento/idea/magento2uct/util/php/MagentoTypeEscapeUtil.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ private MagentoTypeEscapeUtil() {
3232
String result = typeFqn;
3333

3434
while (matcher.find()) {
35-
result = result.substring(0, matcher.start(0)) + result.substring(matcher.end(0));
35+
final int begin = matcher.start(0);
36+
final int end = matcher.end(0);
37+
38+
if (begin < 0 || begin > end || end > result.length()) {
39+
continue;
40+
}
41+
result = result.substring(0, begin) + result.substring(end);
3642
}
3743

3844
return typeFqn.equals(result) ? typeFqn : result;

0 commit comments

Comments
 (0)