12
12
import com .intellij .psi .PsiFile ;
13
13
import com .intellij .psi .codeStyle .CodeStyleManager ;
14
14
import com .intellij .psi .util .PsiTreeUtil ;
15
- import com .intellij .psi .xml .*;
15
+ import com .intellij .psi .xml .XmlAttribute ;
16
+ import com .intellij .psi .xml .XmlAttributeValue ;
17
+ import com .intellij .psi .xml .XmlFile ;
18
+ import com .intellij .psi .xml .XmlTag ;
16
19
import com .jetbrains .php .lang .PhpLangUtil ;
17
20
import com .magento .idea .magento2plugin .actions .generation .data .PluginDiXmlData ;
18
21
import com .magento .idea .magento2plugin .actions .generation .generator .util .FindOrCreateDiXml ;
@@ -36,10 +39,13 @@ public class PluginDiXmlGenerator extends FileGenerator {
36
39
/**
37
40
* Constructor.
38
41
*
39
- * @param pluginFileData
40
- * @param project
42
+ * @param pluginFileData PluginDiXmlData
43
+ * @param project Project
41
44
*/
42
- public PluginDiXmlGenerator (final @ NotNull PluginDiXmlData pluginFileData , final Project project ) {
45
+ public PluginDiXmlGenerator (
46
+ final @ NotNull PluginDiXmlData pluginFileData ,
47
+ final Project project
48
+ ) {
43
49
super (project );
44
50
this .pluginFileData = pluginFileData ;
45
51
this .project = project ;
@@ -56,7 +62,11 @@ public PluginDiXmlGenerator(final @NotNull PluginDiXmlData pluginFileData, final
56
62
*/
57
63
@ Override
58
64
public PsiFile generate (final String actionName ) {
59
- final PsiFile diXmlFile = findOrCreateDiXml .execute (actionName , pluginFileData .getPluginModule (), pluginFileData .getArea ());
65
+ final PsiFile diXmlFile = findOrCreateDiXml .execute (
66
+ actionName ,
67
+ pluginFileData .getPluginModule (),
68
+ pluginFileData .getArea ()
69
+ );
60
70
final XmlAttributeValue typeAttributeValue = getTypeAttributeValue ((XmlFile ) diXmlFile );
61
71
boolean isPluginDeclared = false ;
62
72
this .isTypeDeclared = false ;
@@ -70,16 +80,23 @@ public PsiFile generate(final String actionName) {
70
80
WriteCommandAction .runWriteCommandAction (project , () -> {
71
81
final StringBuffer textBuf = new StringBuffer ();
72
82
try {
73
- textBuf .append (getCodeTemplate .execute (ModuleDiXml .TEMPLATE_PLUGIN , getAttributes ()));
83
+ textBuf .append (getCodeTemplate .execute (
84
+ ModuleDiXml .TEMPLATE_PLUGIN ,
85
+ getAttributes ())
86
+ );
74
87
} catch (IOException e ) {
75
88
return ;
76
89
}
77
90
78
91
final int insertPos = isTypeDeclared
79
- ? positionUtil .getEndPositionOfTag (PsiTreeUtil .getParentOfType (typeAttributeValue , XmlTag .class ))
92
+ ? positionUtil .getEndPositionOfTag (PsiTreeUtil .getParentOfType (
93
+ typeAttributeValue ,
94
+ XmlTag .class
95
+ ))
80
96
: positionUtil .getRootInsertPosition ((XmlFile ) diXmlFile );
81
97
if (textBuf .length () > 0 && insertPos >= 0 ) {
82
- final PsiDocumentManager psiDocumentManager = PsiDocumentManager .getInstance (project );
98
+ final PsiDocumentManager psiDocumentManager =
99
+ PsiDocumentManager .getInstance (project );
83
100
final Document document = psiDocumentManager .getDocument (diXmlFile );
84
101
document .insertString (insertPos , textBuf );
85
102
final int endPos = insertPos + textBuf .length () + 1 ;
@@ -101,7 +118,10 @@ private boolean isPluginDeclared(final XmlAttributeValue typeAttributeValue) {
101
118
if (!child .getName ().equals (ModuleDiXml .PLUGIN_TAG_NAME )) {
102
119
continue ;
103
120
}
104
- final XmlAttribute [] xmlAttributes = PsiTreeUtil .getChildrenOfType (child , XmlAttribute .class );
121
+ final XmlAttribute [] xmlAttributes = PsiTreeUtil .getChildrenOfType (
122
+ child ,
123
+ XmlAttribute .class
124
+ );
105
125
for (final XmlAttribute xmlAttribute : xmlAttributes ) {
106
126
if (!xmlAttribute .getName ().equals (ModuleDiXml .PLUGIN_TYPE_ATTRIBUTE )) {
107
127
continue ;
@@ -117,7 +137,12 @@ private boolean isPluginDeclared(final XmlAttributeValue typeAttributeValue) {
117
137
}
118
138
119
139
private XmlAttributeValue getTypeAttributeValue (final XmlFile diXml ) {
120
- final Collection <XmlAttributeValue > pluginTypes = XmlPsiTreeUtil .findAttributeValueElements (diXml , ModuleDiXml .PLUGIN_TYPE_TAG , ModuleDiXml .PLUGIN_TYPE_ATTR_NAME );
140
+ final Collection <XmlAttributeValue > pluginTypes =
141
+ XmlPsiTreeUtil .findAttributeValueElements (
142
+ diXml ,
143
+ ModuleDiXml .PLUGIN_TYPE_TAG ,
144
+ ModuleDiXml .PLUGIN_TYPE_ATTR_NAME
145
+ );
121
146
final String pluginClassFqn = pluginFileData .getTargetClass ().getPresentableFQN ();
122
147
for (final XmlAttributeValue pluginType : pluginTypes ) {
123
148
if (PhpLangUtil .toPresentableFQN (pluginType .getValue ()).equals (pluginClassFqn )) {
0 commit comments