1212import com .intellij .psi .PsiFile ;
1313import com .intellij .psi .codeStyle .CodeStyleManager ;
1414import 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 ;
1619import com .jetbrains .php .lang .PhpLangUtil ;
1720import com .magento .idea .magento2plugin .actions .generation .data .PluginDiXmlData ;
1821import com .magento .idea .magento2plugin .actions .generation .generator .util .FindOrCreateDiXml ;
@@ -36,10 +39,13 @@ public class PluginDiXmlGenerator extends FileGenerator {
3639 /**
3740 * Constructor.
3841 *
39- * @param pluginFileData
40- * @param project
42+ * @param pluginFileData PluginDiXmlData
43+ * @param project Project
4144 */
42- public PluginDiXmlGenerator (final @ NotNull PluginDiXmlData pluginFileData , final Project project ) {
45+ public PluginDiXmlGenerator (
46+ final @ NotNull PluginDiXmlData pluginFileData ,
47+ final Project project
48+ ) {
4349 super (project );
4450 this .pluginFileData = pluginFileData ;
4551 this .project = project ;
@@ -56,7 +62,11 @@ public PluginDiXmlGenerator(final @NotNull PluginDiXmlData pluginFileData, final
5662 */
5763 @ Override
5864 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+ );
6070 final XmlAttributeValue typeAttributeValue = getTypeAttributeValue ((XmlFile ) diXmlFile );
6171 boolean isPluginDeclared = false ;
6272 this .isTypeDeclared = false ;
@@ -70,16 +80,23 @@ public PsiFile generate(final String actionName) {
7080 WriteCommandAction .runWriteCommandAction (project , () -> {
7181 final StringBuffer textBuf = new StringBuffer ();
7282 try {
73- textBuf .append (getCodeTemplate .execute (ModuleDiXml .TEMPLATE_PLUGIN , getAttributes ()));
83+ textBuf .append (getCodeTemplate .execute (
84+ ModuleDiXml .TEMPLATE_PLUGIN ,
85+ getAttributes ())
86+ );
7487 } catch (IOException e ) {
7588 return ;
7689 }
7790
7891 final int insertPos = isTypeDeclared
79- ? positionUtil .getEndPositionOfTag (PsiTreeUtil .getParentOfType (typeAttributeValue , XmlTag .class ))
92+ ? positionUtil .getEndPositionOfTag (PsiTreeUtil .getParentOfType (
93+ typeAttributeValue ,
94+ XmlTag .class
95+ ))
8096 : positionUtil .getRootInsertPosition ((XmlFile ) diXmlFile );
8197 if (textBuf .length () > 0 && insertPos >= 0 ) {
82- final PsiDocumentManager psiDocumentManager = PsiDocumentManager .getInstance (project );
98+ final PsiDocumentManager psiDocumentManager =
99+ PsiDocumentManager .getInstance (project );
83100 final Document document = psiDocumentManager .getDocument (diXmlFile );
84101 document .insertString (insertPos , textBuf );
85102 final int endPos = insertPos + textBuf .length () + 1 ;
@@ -101,7 +118,10 @@ private boolean isPluginDeclared(final XmlAttributeValue typeAttributeValue) {
101118 if (!child .getName ().equals (ModuleDiXml .PLUGIN_TAG_NAME )) {
102119 continue ;
103120 }
104- final XmlAttribute [] xmlAttributes = PsiTreeUtil .getChildrenOfType (child , XmlAttribute .class );
121+ final XmlAttribute [] xmlAttributes = PsiTreeUtil .getChildrenOfType (
122+ child ,
123+ XmlAttribute .class
124+ );
105125 for (final XmlAttribute xmlAttribute : xmlAttributes ) {
106126 if (!xmlAttribute .getName ().equals (ModuleDiXml .PLUGIN_TYPE_ATTRIBUTE )) {
107127 continue ;
@@ -117,7 +137,12 @@ private boolean isPluginDeclared(final XmlAttributeValue typeAttributeValue) {
117137 }
118138
119139 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+ );
121146 final String pluginClassFqn = pluginFileData .getTargetClass ().getPresentableFQN ();
122147 for (final XmlAttributeValue pluginType : pluginTypes ) {
123148 if (PhpLangUtil .toPresentableFQN (pluginType .getValue ()).equals (pluginClassFqn )) {
0 commit comments