Skip to content

Commit 49afbf2

Browse files
760: Fixed bug
1 parent 9ab192a commit 49afbf2

File tree

3 files changed

+47
-21
lines changed

3 files changed

+47
-21
lines changed

resources/magento2/validation.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ validator.command.isNotValid=The {0} field does not contain a valid Magento 2 CL
2222
validator.module.noSuchModule=No such module {0}
2323
validator.file.alreadyExists={0} already exists
2424
validator.file.cantBeCreated={0} can't be created
25+
validator.file.cantBeCreatedWithException=The ''{0}'' cannot be created. Original message was: ''{1}''
2526
validator.file.isNotWritable=%s file is binary or has no document associations
2627
validator.file.noDocumentAssociations={0} file is binary or has no document associations
2728
validator.class.alreadyDeclared={0} already declared in the target module

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package com.magento.idea.magento2plugin.actions.generation.generator;
77

8+
import com.intellij.openapi.application.ApplicationManager;
89
import com.intellij.openapi.command.WriteCommandAction;
910
import com.intellij.openapi.editor.Document;
1011
import com.intellij.openapi.project.Project;
@@ -88,7 +89,7 @@ public PluginClassGenerator(
8889
*
8990
* @return PsiFile
9091
*/
91-
@SuppressWarnings("PMD.CognitiveComplexity")
92+
@SuppressWarnings({"PMD.CognitiveComplexity", "PMD.ExcessiveMethodLength"})
9293
@Override
9394
public PsiFile generate(final String actionName) {
9495
final PsiFile[] pluginFile = {null};
@@ -100,15 +101,27 @@ public PsiFile generate(final String actionName) {
100101
pluginClass = createPluginClass(actionName);
101102
}
102103
if (pluginClass == null) {
103-
final String errorMessage = validatorBundle.message(
104-
"validator.file.cantBeCreated",
105-
"Plugin Class"
106-
);
107-
JOptionPane.showMessageDialog(
108-
null,
109-
errorMessage,
110-
errorTitle,
111-
JOptionPane.ERROR_MESSAGE
104+
String errorMessage;
105+
106+
if (fileFromTemplateGenerator.getLastExceptionMessage() == null) {
107+
errorMessage = validatorBundle.message(
108+
"validator.file.cantBeCreated",
109+
"Plugin Class"
110+
);
111+
} else {
112+
errorMessage = validatorBundle.message(
113+
"validator.file.cantBeCreatedWithException",
114+
"Plugin Class",
115+
fileFromTemplateGenerator.getLastExceptionMessage()
116+
);
117+
}
118+
ApplicationManager.getApplication().invokeLater(
119+
() -> JOptionPane.showMessageDialog(
120+
null,
121+
errorMessage,
122+
errorTitle,
123+
JOptionPane.ERROR_MESSAGE
124+
)
112125
);
113126

114127
return;
@@ -132,11 +145,13 @@ public PsiFile generate(final String actionName) {
132145
"validator.file.alreadyExists",
133146
"Plugin Class"
134147
);
135-
JOptionPane.showMessageDialog(
136-
null,
137-
errorMessage,
138-
errorTitle,
139-
JOptionPane.ERROR_MESSAGE
148+
ApplicationManager.getApplication().invokeLater(
149+
() -> JOptionPane.showMessageDialog(
150+
null,
151+
errorMessage,
152+
errorTitle,
153+
JOptionPane.ERROR_MESSAGE
154+
)
140155
);
141156

142157
return;

src/com/magento/idea/magento2plugin/actions/generation/generator/util/FileFromTemplateGenerator.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.intellij.openapi.application.ApplicationManager;
1313
import com.intellij.openapi.command.CommandProcessor;
1414
import com.intellij.openapi.project.Project;
15-
import com.intellij.openapi.ui.Messages;
1615
import com.intellij.openapi.util.Ref;
1716
import com.intellij.openapi.util.text.StringUtil;
1817
import com.intellij.psi.PsiDirectory;
@@ -33,6 +32,7 @@
3332
public class FileFromTemplateGenerator {
3433

3534
private final @NotNull Project project;
35+
private @Nullable String exceptionMessage;
3636

3737
public FileFromTemplateGenerator(final @NotNull Project project) {
3838
this.project = project;
@@ -45,17 +45,18 @@ public FileFromTemplateGenerator(final @NotNull Project project) {
4545
* @param attributes Properties
4646
* @param baseDir PsiDirectory
4747
* @param actionName String
48+
*
4849
* @return PsiFile
4950
*/
50-
@Nullable
51-
public PsiFile generate(
51+
public @Nullable PsiFile generate(
5252
final @NotNull ModuleFileInterface moduleFile,
5353
final @NotNull Properties attributes,
5454
final @NotNull PsiDirectory baseDir,
5555
final @NotNull String actionName
5656
) {
5757
final Ref<PsiFile> fileRef = new Ref<>(null);
5858
final Ref<String> exceptionRef = new Ref<>(null);
59+
exceptionMessage = null;
5960
final String filePath = baseDir.getText().concat("/").concat(moduleFile.getFileName());
6061

6162
CommandProcessor.getInstance().executeCommand(project, () -> {
@@ -66,8 +67,8 @@ public PsiFile generate(
6667
if (file != null) {
6768
fileRef.set(file);
6869
}
69-
} catch (IncorrectOperationException | IOException var9) {
70-
exceptionRef.set(var9.getMessage());
70+
} catch (IncorrectOperationException | IOException exception) {
71+
exceptionRef.set(exception.getMessage());
7172
}
7273
};
7374
ApplicationManager.getApplication().runWriteAction(run);
@@ -76,11 +77,20 @@ public PsiFile generate(
7677
if (exceptionRef.isNull()) {
7778
return fileRef.get();
7879
}
80+
exceptionMessage = exceptionRef.get();
7981

80-
Messages.showErrorDialog(exceptionRef.get(), actionName);
8182
return null;
8283
}
8384

85+
/**
86+
* Get last thrown exception message if exists.
87+
*
88+
* @return String
89+
*/
90+
public @Nullable String getLastExceptionMessage() {
91+
return exceptionMessage;
92+
}
93+
8494
@Nullable
8595
private PsiFile createFile(
8696
final @NotNull ModuleFileInterface moduleFile,

0 commit comments

Comments
 (0)