Skip to content

Commit f6ec3e3

Browse files
committed
1269: fixed AWT events are not allowed inside write action
1 parent 2b39dde commit f6ec3e3

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,48 +65,52 @@ public ModuleGraphQlResolverClassGenerator(
6565
@Override
6666
public PsiFile generate(final String actionName) {
6767
final PsiFile[] graphQlFile = {null};
68-
WriteCommandAction.runWriteCommandAction(project, () -> {
69-
PhpClass graphQlResolverClass = GetPhpClassByFQN.getInstance(project)
70-
.execute(graphQlResolverFileData.getGraphQlResolverClassFqn());
7168

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

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

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)