Skip to content

Commit 5571554

Browse files
committed
Merge remote-tracking branch 'origin/5.0.1-develop' into 1215_fix_parsing_of_plugin_sort_order_value_backport
# Conflicts: # CHANGELOG.md
2 parents 461da9b + 34979cc commit 5571554

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0).
1111
- Throwable: Stub index points to a file without PSI [#1232](https://github.com/magento/magento2-phpstorm-plugin/pull/1232)
1212
- Create an entity - delete button is displayed in a new entity form [#1268](https://github.com/magento/magento2-phpstorm-plugin/pull/1268)
1313
- Covered possible NullPointerException in InjectAViewModelDialog.java [#1213](https://github.com/magento/magento2-phpstorm-plugin/pull/1213)
14+
- AWT events are not allowed inside write action [#1271](https://github.com/magento/magento2-phpstorm-plugin/pull/1271)
1415
- MapReduceIndexMappingException: java.lang.NumberFormatException: For input string: "" [#1235](https://github.com/magento/magento2-phpstorm-plugin/pull/1235)
1516

1617
## 5.0.0

src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleGraphQlResolverClassGenerator.java

+28-24
Original file line numberDiff line numberDiff line change
@@ -64,49 +64,53 @@ public ModuleGraphQlResolverClassGenerator(
6464

6565
@Override
6666
public PsiFile generate(final String actionName) {
67-
final PsiFile[] graphQlFile = {null};
68-
WriteCommandAction.runWriteCommandAction(project, () -> {
69-
PhpClass graphQlResolverClass = GetPhpClassByFQN.getInstance(project)
70-
.execute(graphQlResolverFileData.getGraphQlResolverClassFqn());
7167

72-
if (graphQlResolverClass == null) {
73-
graphQlResolverClass = createGraphQlResolverClass(actionName);
74-
}
68+
final PhpClass[] graphQlResolverClass = {GetPhpClassByFQN.getInstance(project)
69+
.execute(graphQlResolverFileData.getGraphQlResolverClassFqn())};
7570

76-
if (graphQlResolverClass == null) {
77-
final String errorMessage = validatorBundle.message(
78-
"validator.file.cantBeCreated",
79-
"GraphQL Resolver Class"
80-
);
81-
JOptionPane.showMessageDialog(
82-
null,
83-
errorMessage,
84-
commonBundle.message("common.error"),
85-
JOptionPane.ERROR_MESSAGE
86-
);
87-
88-
return;
89-
}
71+
if (graphQlResolverClass[0] == null) {
72+
WriteCommandAction.runWriteCommandAction(project, () -> {
73+
graphQlResolverClass[0] = createGraphQlResolverClass(actionName);
74+
});
75+
}
76+
77+
if (graphQlResolverClass[0] == null) {
78+
final String errorMessage = validatorBundle.message(
79+
"validator.file.cantBeCreated",
80+
"GraphQL Resolver Class"
81+
);
82+
JOptionPane.showMessageDialog(
83+
null,
84+
errorMessage,
85+
commonBundle.message("common.error"),
86+
JOptionPane.ERROR_MESSAGE
87+
);
88+
89+
return null;
90+
}
9091

92+
final PsiFile[] graphQlFile = {null};
93+
WriteCommandAction.runWriteCommandAction(project, () -> {
9194
final Properties attributes = new Properties();
9295
final String methodTemplate = PhpCodeUtil.getCodeTemplate(
9396
GraphQlResolverPhp.GRAPHQL_RESOLVER_TEMPLATE_NAME, attributes, project);
9497

95-
graphQlFile[0] = graphQlResolverClass.getContainingFile();
98+
graphQlFile[0] = graphQlResolverClass[0].getContainingFile();
9699
final CodeStyleSettings codeStyleSettings = new CodeStyleSettings(
97100
(PhpFile) graphQlFile[0]
98101
);
99102
codeStyleSettings.adjustBeforeWrite();
100103

101104
final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
102105
final Document document = psiDocumentManager.getDocument(graphQlFile[0]);
103-
final int insertPos = getInsertPos(graphQlResolverClass);
106+
final int insertPos = getInsertPos(graphQlResolverClass[0]);
104107
document.insertString(insertPos, methodTemplate);
105108
final int endPos = insertPos + methodTemplate.length() + 1;
106109
CodeStyleManager.getInstance(project).reformatText(graphQlFile[0], insertPos, endPos);
107110
psiDocumentManager.commitDocument(document);
108111
codeStyleSettings.restore();
109112
});
113+
110114
return graphQlFile[0];
111115
}
112116

@@ -116,7 +120,7 @@ private int getInsertPos(final PhpClass graphQlResolverClass) {
116120
graphQlResolverClass,
117121
LeafPsiElement.class
118122
);
119-
for (final LeafPsiElement leafPsiElement: leafElements) {
123+
for (final LeafPsiElement leafPsiElement : leafElements) {
120124
if (!MagentoPhpClass.CLOSING_TAG.equals(leafPsiElement.getText())) {
121125
continue;
122126
}

0 commit comments

Comments
 (0)