@@ -30,57 +30,62 @@ public class PhpServiceArgumentIntention extends PsiElementBaseIntentionAction {
30
30
@ Override
31
31
public void invoke (@ NotNull Project project , Editor editor , @ NotNull PsiElement psiElement ) throws IncorrectOperationException {
32
32
PhpClass phpClass = PsiTreeUtil .getParentOfType (psiElement , PhpClass .class );
33
- if (phpClass != null ) {
34
- Set <String > serviceNames = ContainerCollectionResolver .ServiceCollector .create (project ).convertClassNameToServices (phpClass .getFQN ());
35
- if (serviceNames .size () > 0 ) {
36
- Collection <PsiElement > psiElements = new ArrayList <>();
37
- for (String serviceName : serviceNames ) {
38
- psiElements .addAll (ServiceIndexUtil .findServiceDefinitions (project , serviceName ));
39
- }
40
-
41
- if (psiElements .size () > 0 ) {
42
- Map <String , PsiElement > map = new HashMap <>();
43
-
44
- for (PsiElement element : psiElements ) {
45
- map .put (VfsUtil .getRelativePath (element .getContainingFile ().getVirtualFile (), element .getProject ().getBaseDir ()), element );
46
- }
47
-
48
- final JBList <String > list = new JBList <>(map .keySet ());
49
-
50
- JBPopupFactory .getInstance ().createListPopupBuilder (list )
51
- .setTitle ("Symfony: Services Definitions" )
52
- .setItemChoosenCallback (() -> new WriteCommandAction .Simple (editor .getProject (), "Service Update" ) {
53
- @ Override
54
- protected void run () {
55
- String selectedValue = list .getSelectedValue ();
56
-
57
- PsiElement target = map .get (selectedValue );
58
- invokeByScope (target , editor );
59
- }
60
- }.execute ())
61
- .createPopup ()
62
- .showInBestPositionFor (editor );
63
- }
64
- }
33
+ if (phpClass == null ) {
34
+
35
+ return ;
36
+ }
37
+
38
+ Set <String > serviceNames = ContainerCollectionResolver .ServiceCollector .create (project ).convertClassNameToServices (phpClass .getFQN ());
39
+ if (serviceNames .isEmpty ()) {
40
+
41
+ return ;
42
+ }
43
+
44
+ Collection <PsiElement > psiElements = new ArrayList <>();
45
+ for (String serviceName : serviceNames ) {
46
+ psiElements .addAll (ServiceIndexUtil .findServiceDefinitions (project , serviceName ));
65
47
}
48
+
49
+ if (psiElements .isEmpty ()) {
50
+
51
+ return ;
52
+ }
53
+
54
+ Map <String , PsiElement > map = new HashMap <>();
55
+
56
+ for (PsiElement element : psiElements ) {
57
+ map .put (VfsUtil .getRelativePath (element .getContainingFile ().getVirtualFile (), element .getProject ().getBaseDir ()), element );
58
+ }
59
+
60
+ final JBList <String > list = new JBList <>(map .keySet ());
61
+ JBPopupFactory .getInstance ().createListPopupBuilder (list )
62
+ .setTitle ("Symfony: Services Definitions" )
63
+ .setItemChoosenCallback (() -> {
64
+ WriteCommandAction .writeCommandAction (project ).withName ("Service Update" ).run (() -> {
65
+ invokeByScope (map .get (list .getSelectedValue ()), editor );
66
+ });
67
+ })
68
+ .createPopup ()
69
+ .showInBestPositionFor (editor )
70
+ ;
66
71
}
67
72
68
73
private void invokeByScope (@ NotNull PsiElement psiElement , @ NotNull Editor editor ) {
69
74
boolean success = false ;
70
75
71
- if (psiElement instanceof XmlTag ) {
76
+ if (psiElement instanceof XmlTag ) {
72
77
List <String > args = ServiceActionUtil .getXmlMissingArgumentTypes ((XmlTag ) psiElement , true , new ContainerCollectionResolver .LazyServiceCollector (psiElement .getProject ()));
73
78
74
79
success = args .size () > 0 ;
75
80
if (success ) {
76
81
ServiceActionUtil .fixServiceArgument (args , (XmlTag ) psiElement );
77
82
}
78
- } else if (psiElement instanceof YAMLKeyValue ) {
83
+ } else if (psiElement instanceof YAMLKeyValue ) {
79
84
List <String > args = ServiceActionUtil .getYamlMissingArgumentTypes (
80
- psiElement .getProject (),
81
- ServiceActionUtil .ServiceYamlContainer .create ((YAMLKeyValue ) psiElement ),
82
- false ,
83
- new ContainerCollectionResolver .LazyServiceCollector (psiElement .getProject ())
85
+ psiElement .getProject (),
86
+ ServiceActionUtil .ServiceYamlContainer .create ((YAMLKeyValue ) psiElement ),
87
+ false ,
88
+ new ContainerCollectionResolver .LazyServiceCollector (psiElement .getProject ())
84
89
);
85
90
86
91
success = args .size () > 0 ;
@@ -89,13 +94,14 @@ private void invokeByScope(@NotNull PsiElement psiElement, @NotNull Editor edito
89
94
}
90
95
}
91
96
92
- if (!success ) {
97
+ if (!success ) {
93
98
HintManager .getInstance ().showErrorHint (editor , "No argument update needed" );
99
+
94
100
return ;
95
101
}
96
102
97
103
String relativePath = VfsUtil .getRelativePath (psiElement .getContainingFile ().getVirtualFile (), psiElement .getProject ().getBaseDir ());
98
- if (relativePath == null ) {
104
+ if (relativePath == null ) {
99
105
relativePath = "n/a" ;
100
106
}
101
107
@@ -125,7 +131,7 @@ private Set<String> getServicesInScope(@NotNull PsiElement psiElement) {
125
131
PhpClass phpClass = PsiTreeUtil .getParentOfType (psiElement , PhpClass .class );
126
132
127
133
return phpClass == null
128
- ? Collections .emptySet ()
129
- : ContainerCollectionResolver .ServiceCollector .create (psiElement .getProject ()).convertClassNameToServices (phpClass .getFQN ());
134
+ ? Collections .emptySet ()
135
+ : ContainerCollectionResolver .ServiceCollector .create (psiElement .getProject ()).convertClassNameToServices (phpClass .getFQN ());
130
136
}
131
137
}
0 commit comments