| 
4 | 4 | import com.intellij.codeInsight.daemon.LineMarkerProvider;  | 
5 | 5 | import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo;  | 
6 | 6 | import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder;  | 
 | 7 | +import com.intellij.icons.AllIcons;  | 
7 | 8 | import com.intellij.openapi.project.Project;  | 
8 | 9 | import com.intellij.openapi.util.NotNullLazyValue;  | 
9 | 10 | import com.intellij.openapi.util.Pair;  | 
@@ -76,6 +77,10 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu  | 
76 | 77 |  this.constraintValidatorClassMarker(psiElement, results);  | 
77 | 78 |  }  | 
78 | 79 | 
 
  | 
 | 80 | + if(PhpElementsUtil.getClassMethodNamePattern().accepts(psiElement)) {  | 
 | 81 | + this.autowireConstructorMarker(psiElement, results);  | 
 | 82 | + }  | 
 | 83 | + | 
79 | 84 |  if(psiElement instanceof PhpFile) {  | 
80 | 85 |  routeAnnotationFileResource((PhpFile) psiElement, results);  | 
81 | 86 |  }  | 
@@ -307,10 +312,70 @@ private void constraintValidatorClassMarker(PsiElement psiElement, Collection<Li  | 
307 | 312 |  results.add(builder.createLineMarkerInfo(psiElement));  | 
308 | 313 |  }  | 
309 | 314 | 
 
  | 
 | 315 | + private void autowireConstructorMarker(PsiElement psiElement, Collection<LineMarkerInfo> results) {  | 
 | 316 | + PsiElement method = psiElement.getParent();  | 
 | 317 | + if (!(method instanceof Method)) {  | 
 | 318 | + return;  | 
 | 319 | + }  | 
 | 320 | + | 
 | 321 | + if (!"__construct".equals(((Method) method).getName())) {  | 
 | 322 | + return;  | 
 | 323 | + }  | 
 | 324 | + | 
 | 325 | + PhpClass phpClass = ((Method) method).getContainingClass();  | 
 | 326 | + if (phpClass == null) {  | 
 | 327 | + return;  | 
 | 328 | + }  | 
 | 329 | + | 
 | 330 | + boolean isAutowire = false;  | 
 | 331 | + | 
 | 332 | + Pair<ClassServiceDefinitionTargetLazyValue, Collection<ContainerService>> serviceDefinitionsOfResource = ServiceIndexUtil.findServiceDefinitionsOfResourceLazy(phpClass);  | 
 | 333 | + if (serviceDefinitionsOfResource != null) {  | 
 | 334 | + for (ContainerService containerService : serviceDefinitionsOfResource.getSecond()) {  | 
 | 335 | + ServiceInterface service = containerService.getService();  | 
 | 336 | + if (service == null) {  | 
 | 337 | + continue;  | 
 | 338 | + }  | 
 | 339 | + | 
 | 340 | + if (service.isAutowire()) {  | 
 | 341 | + isAutowire = true;  | 
 | 342 | + break;  | 
 | 343 | + }  | 
 | 344 | + }  | 
 | 345 | + }  | 
 | 346 | + | 
 | 347 | + // direct service  | 
 | 348 | + if (!isAutowire) {  | 
 | 349 | + ContainerCollectionResolver.ServiceCollector serviceCollector = ContainerCollectionResolver.ServiceCollector.create(phpClass.getProject());  | 
 | 350 | + for (String convertClassNameToService : serviceCollector.convertClassNameToServices(phpClass.getFQN())) {  | 
 | 351 | + ContainerService containerService = serviceCollector.getServices().get(convertClassNameToService);  | 
 | 352 | + if (containerService == null) {  | 
 | 353 | + continue;  | 
 | 354 | + }  | 
 | 355 | + | 
 | 356 | + ServiceInterface service = containerService.getService();  | 
 | 357 | + if (service != null && service.isAutowire()) {  | 
 | 358 | + isAutowire = true;  | 
 | 359 | + break;  | 
 | 360 | + }  | 
 | 361 | + }  | 
 | 362 | + }  | 
 | 363 | + | 
 | 364 | + if (!isAutowire) {  | 
 | 365 | + return;  | 
 | 366 | + }  | 
 | 367 | + | 
 | 368 | + NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(AllIcons.Nodes.Plugin)  | 
 | 369 | + .setTargets(new MyCollectionNotNullLazyValue(Collections.emptyList()))  | 
 | 370 | + .setTooltipText("Symfony: <a href=\"https://symfony.com/doc/current/service_container/autowiring.html\">Autowire available</a>");  | 
 | 371 | + | 
 | 372 | + results.add(builder.createLineMarkerInfo(psiElement));  | 
 | 373 | + }  | 
 | 374 | + | 
310 | 375 |  private static class MyCollectionNotNullLazyValue extends NotNullLazyValue<Collection<? extends PsiElement>> {  | 
311 | 376 |  private final Collection<ClassServiceDefinitionTargetLazyValue> targets;  | 
312 | 377 | 
 
  | 
313 |  | - public MyCollectionNotNullLazyValue(Collection<ClassServiceDefinitionTargetLazyValue> targets) {  | 
 | 378 | + public MyCollectionNotNullLazyValue(@NotNull Collection<ClassServiceDefinitionTargetLazyValue> targets) {  | 
314 | 379 |  this.targets = targets;  | 
315 | 380 |  }  | 
316 | 381 | 
 
  | 
 | 
0 commit comments