2
2
* Copyright © Magento, Inc. All rights reserved.
3
3
* See COPYING.txt for license details.
4
4
*/
5
+
5
6
package com .magento .idea .magento2plugin .actions .generation ;
6
7
7
8
import com .intellij .openapi .actionSystem .AnActionEvent ;
17
18
import com .jetbrains .php .lang .psi .elements .PhpClass ;
18
19
import com .magento .idea .magento2plugin .MagentoIcons ;
19
20
import com .magento .idea .magento2plugin .actions .generation .dialog .CreateAPluginDialog ;
21
+ import com .magento .idea .magento2plugin .project .Settings ;
20
22
import com .magento .idea .magento2plugin .util .GetFirstClassOfFile ;
21
23
import com .magento .idea .magento2plugin .util .magento .plugin .IsPluginAllowedForMethod ;
22
24
import org .jetbrains .annotations .NotNull ;
23
- import com .magento .idea .magento2plugin .project .Settings ;
24
25
25
26
public class CreateAPluginAction extends DumbAwareAction {
26
27
public static final String ACTION_NAME = "Create a new Plugin for this method" ;
@@ -30,12 +31,18 @@ public class CreateAPluginAction extends DumbAwareAction {
30
31
private Method targetMethod ;
31
32
private PhpClass targetClass ;
32
33
34
+ /**
35
+ * Constructor.
36
+ */
33
37
public CreateAPluginAction () {
34
38
super (ACTION_NAME , ACTION_DESCRIPTION , MagentoIcons .MODULE );
35
39
this .isPluginAllowed = IsPluginAllowedForMethod .getInstance ();
36
40
this .getFirstClassOfFile = GetFirstClassOfFile .getInstance ();
37
41
}
38
42
43
+ /**
44
+ * Updates the state of action.
45
+ */
39
46
@ Override
40
47
public void update (final AnActionEvent event ) {
41
48
targetClass = null ;// NOPMD
@@ -46,9 +53,9 @@ public void update(final AnActionEvent event) {
46
53
final PsiFile psiFile = pair .getFirst ();
47
54
final PhpClass phpClass = pair .getSecond ();
48
55
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
52
59
) {
53
60
this .setStatus (event , false );
54
61
return ;
@@ -88,7 +95,11 @@ private Pair<PsiFile, PhpClass> findPhpClass(@NotNull final AnActionEvent event)
88
95
return Pair .create (psiFile , phpClass );
89
96
}
90
97
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
+ ) {
92
103
final Caret caret = event .getData (PlatformDataKeys .CARET );
93
104
if (caret == null ) {
94
105
return ;
@@ -98,12 +109,14 @@ private void fetchTargetMethod(@NotNull final AnActionEvent event, final PsiFile
98
109
if (element == null ) {
99
110
return ;
100
111
}
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 )) {
102
114
this .targetMethod = (Method ) element ;
103
115
return ;
104
116
}
105
117
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 )) {
107
120
this .targetMethod = (Method ) parent ;
108
121
}
109
122
}
0 commit comments