22 * Copyright © Magento, Inc. All rights reserved.
33 * See COPYING.txt for license details.
44 */
5+
56package com .magento .idea .magento2plugin .actions .generation ;
67
78import com .intellij .openapi .actionSystem .AnActionEvent ;
1718import com .jetbrains .php .lang .psi .elements .PhpClass ;
1819import com .magento .idea .magento2plugin .MagentoIcons ;
1920import com .magento .idea .magento2plugin .actions .generation .dialog .CreateAPluginDialog ;
21+ import com .magento .idea .magento2plugin .project .Settings ;
2022import com .magento .idea .magento2plugin .util .GetFirstClassOfFile ;
2123import com .magento .idea .magento2plugin .util .magento .plugin .IsPluginAllowedForMethod ;
2224import org .jetbrains .annotations .NotNull ;
23- import com .magento .idea .magento2plugin .project .Settings ;
2425
2526public class CreateAPluginAction extends DumbAwareAction {
2627 public static final String ACTION_NAME = "Create a new Plugin for this method" ;
@@ -30,12 +31,18 @@ public class CreateAPluginAction extends DumbAwareAction {
3031 private Method targetMethod ;
3132 private PhpClass targetClass ;
3233
34+ /**
35+ * Constructor.
36+ */
3337 public CreateAPluginAction () {
3438 super (ACTION_NAME , ACTION_DESCRIPTION , MagentoIcons .MODULE );
3539 this .isPluginAllowed = IsPluginAllowedForMethod .getInstance ();
3640 this .getFirstClassOfFile = GetFirstClassOfFile .getInstance ();
3741 }
3842
43+ /**
44+ * Updates the state of action.
45+ */
3946 @ Override
4047 public void update (final AnActionEvent event ) {
4148 targetClass = null ;// NOPMD
@@ -46,9 +53,9 @@ public void update(final AnActionEvent event) {
4653 final PsiFile psiFile = pair .getFirst ();
4754 final PhpClass phpClass = pair .getSecond ();
4855 if (phpClass == null
49- || !(psiFile instanceof PhpFile )
50- || phpClass .isFinal ()
51- || this .targetMethod == null
56+ || !(psiFile instanceof PhpFile )
57+ || phpClass .isFinal ()
58+ || this .targetMethod == null
5259 ) {
5360 this .setStatus (event , false );
5461 return ;
@@ -88,7 +95,11 @@ private Pair<PsiFile, PhpClass> findPhpClass(@NotNull final AnActionEvent event)
8895 return Pair .create (psiFile , phpClass );
8996 }
9097
91- private void fetchTargetMethod (@ NotNull final AnActionEvent event , final PsiFile psiFile , final PhpClass phpClass ) {
98+ private void fetchTargetMethod (
99+ @ NotNull final AnActionEvent event ,
100+ final PsiFile psiFile ,
101+ final PhpClass phpClass
102+ ) {
92103 final Caret caret = event .getData (PlatformDataKeys .CARET );
93104 if (caret == null ) {
94105 return ;
@@ -98,12 +109,14 @@ private void fetchTargetMethod(@NotNull final AnActionEvent event, final PsiFile
98109 if (element == null ) {
99110 return ;
100111 }
101- if (element instanceof Method && element .getParent () == phpClass && isPluginAllowed .check ((Method ) element )) {
112+ if (element instanceof Method && element .getParent ()
113+ == phpClass && isPluginAllowed .check ((Method ) element )) {
102114 this .targetMethod = (Method ) element ;
103115 return ;
104116 }
105117 final PsiElement parent = element .getParent ();
106- if (parent instanceof Method && parent .getParent () == phpClass && isPluginAllowed .check ((Method ) parent )) {
118+ if (parent instanceof Method && parent .getParent ()
119+ == phpClass && isPluginAllowed .check ((Method ) parent )) {
107120 this .targetMethod = (Method ) parent ;
108121 }
109122 }
0 commit comments