77import com .intellij .icons .AllIcons ;
88import com .intellij .openapi .project .Project ;
99import com .intellij .openapi .util .NotNullLazyValue ;
10- import com .intellij .openapi .util .Pair ;
1110import com .intellij .openapi .vfs .VirtualFile ;
1211import com .intellij .psi .PsiElement ;
1312import com .intellij .psi .PsiFile ;
2221import fr .adrienbrault .idea .symfony2plugin .Symfony2ProjectComponent ;
2322import fr .adrienbrault .idea .symfony2plugin .dic .ClassServiceDefinitionTargetLazyValue ;
2423import fr .adrienbrault .idea .symfony2plugin .dic .ContainerService ;
24+ import fr .adrienbrault .idea .symfony2plugin .dic .ContainerServiceMetadata ;
2525import fr .adrienbrault .idea .symfony2plugin .dic .container .ServiceInterface ;
2626import fr .adrienbrault .idea .symfony2plugin .doctrine .metadata .util .DoctrineMetadataUtil ;
2727import fr .adrienbrault .idea .symfony2plugin .form .util .FormUtil ;
2828import fr .adrienbrault .idea .symfony2plugin .stubs .ContainerCollectionResolver ;
29- import fr .adrienbrault .idea .symfony2plugin .stubs .ServiceIndexUtil ;
3029import fr .adrienbrault .idea .symfony2plugin .translation .ConstraintMessageGotoCompletionRegistrar ;
3130import fr .adrienbrault .idea .symfony2plugin .translation .dict .TranslationUtil ;
3231import fr .adrienbrault .idea .symfony2plugin .util .PhpElementsUtil ;
@@ -103,47 +102,37 @@ private void classNameMarker(@NotNull Project project, @NotNull PsiElement psiEl
103102 Icon serviceLineMarker = ExternalSystemIcons .Task ;
104103 Collection <ClassServiceDefinitionTargetLazyValue > targets = new ArrayList <>();
105104 Collection <String > tags = new HashSet <>();
106-
107- // a direct service match
108- ClassServiceDefinitionTargetLazyValue psiElements = ServiceIndexUtil .findServiceDefinitionsLazy ((PhpClass ) phpClassContext );
109- if (psiElements != null ) {
110- targets .add (psiElements );
111-
112- // tags
113- ContainerCollectionResolver .ServiceCollector serviceCollector = ContainerCollectionResolver .ServiceCollector .create (project );
114- for (String convertClassNameToService : serviceCollector .convertClassNameToServices (((PhpClass ) phpClassContext ).getFQN ())) {
115- tags .addAll (ServiceUtil .getServiceTags (project , convertClassNameToService ));
116-
117- ContainerService containerService = serviceCollector .getServices ().get (convertClassNameToService );
118- if (containerService != null ) {
119- ServiceInterface service = containerService .getService ();
120- if (service != null ) {
121- tags .addAll (service .getTags ());
122- }
123- }
124- }
105+ ContainerCollectionResolver .ServiceCollector serviceCollector = ContainerCollectionResolver .ServiceCollector .create (project );
106+ Set <String > serviceNames = serviceCollector .convertClassNameToServices (((PhpClass ) phpClassContext ).getFQN ());
107+ if (serviceNames .isEmpty ()) {
108+ return ;
125109 }
126110
127- // via resource include
128- Pair < ClassServiceDefinitionTargetLazyValue , Collection < ContainerService >> serviceDefinitionsOfResource = ServiceIndexUtil . findServiceDefinitionsOfResourceLazy (( PhpClass ) phpClassContext );
129- if (serviceDefinitionsOfResource != null ) {
111+ targets . add ( new ClassServiceDefinitionTargetLazyValue ( project , (( PhpClass ) phpClassContext ). getFQN ()));
112+
113+ if (hasResourcePrototypeMetadata ( serviceNames , serviceCollector ) ) {
130114 LayeredIcon serviceLineMarkerLayer = LayeredIcon .layeredIcon (new Icon []{serviceLineMarker , AllIcons .Modules .SourceRootFileLayer });
131115 serviceLineMarkerLayer .setIcon (AllIcons .Modules .SourceRootFileLayer , 1 , SwingConstants .CENTER );
132116
133117 serviceLineMarker = serviceLineMarkerLayer ;
134- targets .add (serviceDefinitionsOfResource .getFirst ());
135-
136- // tags
137- for (ContainerService containerService : serviceDefinitionsOfResource .getSecond ()) {
138- ServiceInterface service = containerService .getService ();
139- if (service != null ) {
140- tags .addAll (ServiceUtil .getServiceTags (project , service .getId ()));
141- }
142- }
143118 }
144119
145- if (targets .isEmpty ()) {
146- return ;
120+ for (String serviceName : serviceNames ) {
121+ tags .addAll (ServiceUtil .getServiceTags (project , serviceName ));
122+
123+ ContainerService containerService = serviceCollector .getServices ().get (serviceName );
124+ if (containerService == null ) {
125+ continue ;
126+ }
127+
128+ ServiceInterface service = containerService .getService ();
129+ if (service != null ) {
130+ tags .addAll (service .getTags ());
131+ }
132+
133+ for (ContainerServiceMetadata metadata : containerService .getMetadata ()) {
134+ tags .addAll (metadata .tags ());
135+ }
147136 }
148137
149138 if (!tags .isEmpty ()) {
@@ -320,36 +309,17 @@ private void autowireConstructorMarker(@NotNull Project project, @NotNull PsiEle
320309 boolean isAutowire = false ;
321310
322311 Collection <ClassServiceDefinitionTargetLazyValue > targets = new ArrayList <>();
323-
324- Pair <ClassServiceDefinitionTargetLazyValue , Collection <ContainerService >> serviceDefinitionsOfResource = ServiceIndexUtil .findServiceDefinitionsOfResourceLazy (phpClass );
325- if (serviceDefinitionsOfResource != null ) {
326- for (ContainerService containerService : serviceDefinitionsOfResource .getSecond ()) {
327- ServiceInterface service = containerService .getService ();
328- if (service == null ) {
329- continue ;
330- }
331-
332- if (service .isAutowire ()) {
333- isAutowire = true ;
334- targets .add (serviceDefinitionsOfResource .getFirst ());
335- }
312+ ContainerCollectionResolver .ServiceCollector serviceCollector = ContainerCollectionResolver .ServiceCollector .create (project );
313+ for (String convertClassNameToService : serviceCollector .convertClassNameToServices (phpClass .getFQN ())) {
314+ ContainerService containerService = serviceCollector .getServices ().get (convertClassNameToService );
315+ if (containerService == null ) {
316+ continue ;
336317 }
337- }
338318
339- // direct service
340- if (!isAutowire ) {
341- ContainerCollectionResolver .ServiceCollector serviceCollector = ContainerCollectionResolver .ServiceCollector .create (project );
342- for (String convertClassNameToService : serviceCollector .convertClassNameToServices (phpClass .getFQN ())) {
343- ContainerService containerService = serviceCollector .getServices ().get (convertClassNameToService );
344- if (containerService == null ) {
345- continue ;
346- }
347-
348- ServiceInterface service = containerService .getService ();
349- if (service != null && service .isAutowire ()) {
350- isAutowire = true ;
351- targets .add (new ClassServiceDefinitionTargetLazyValue (project , convertClassNameToService ));
352- }
319+ if (containerService .isAutowireEnabled ()) {
320+ isAutowire = true ;
321+ targets .add (new ClassServiceDefinitionTargetLazyValue (project , phpClass .getFQN ()));
322+ break ;
353323 }
354324 }
355325
@@ -364,6 +334,17 @@ private void autowireConstructorMarker(@NotNull Project project, @NotNull PsiEle
364334 results .add (builder .createLineMarkerInfo (psiElement ));
365335 }
366336
337+ private static boolean hasResourcePrototypeMetadata (@ NotNull Collection <String > serviceNames , @ NotNull ContainerCollectionResolver .ServiceCollector serviceCollector ) {
338+ for (String serviceName : serviceNames ) {
339+ ContainerService containerService = serviceCollector .getServices ().get (serviceName );
340+ if (containerService != null && containerService .hasResourcePrototypeMetadata ()) {
341+ return true ;
342+ }
343+ }
344+
345+ return false ;
346+ }
347+
367348 private void constraintMessagePropertyMarker (@ NotNull PsiElement psiElement , @ NotNull Collection <? super LineMarkerInfo <?>> results ) {
368349 PsiElement parent = psiElement .getParent ();
369350 if (parent instanceof StringLiteralExpression && TranslationUtil .isConstraintPropertyField ((StringLiteralExpression ) parent )) {
@@ -395,4 +376,3 @@ public Collection<? extends PsiElement> get() {
395376 }
396377 }
397378}
398-
0 commit comments