File tree Expand file tree Collapse file tree 3 files changed +41
-5
lines changed
main/java/fr/adrienbrault/idea/symfony2plugin/codeInsight
test/java/fr/adrienbrault/idea/symfony2plugin/tests/codeInsight Expand file tree Collapse file tree 3 files changed +41
-5
lines changed Original file line number Diff line number Diff line change 1414import org .apache .commons .lang .StringUtils ;
1515import org .jetbrains .annotations .NotNull ;
1616
17- import java .util .Arrays ;
18- import java .util .Collection ;
19- import java .util .HashSet ;
20- import java .util .Set ;
17+ import java .util .*;
2118import java .util .stream .Collectors ;
2219
2320/**
@@ -40,12 +37,24 @@ public boolean isImplicitUsage(@NotNull PsiElement element) {
4037 || isSubscribedEvent ((PhpClass ) element )
4138 || isVoter ((PhpClass ) element )
4239 || isTwigExtension ((PhpClass ) element )
43- || isEntityRepository ((PhpClass ) element );
40+ || isEntityRepository ((PhpClass ) element )
41+ || isConstraint ((PhpClass ) element );
4442 }
4543
4644 return false ;
4745 }
4846
47+ private boolean isConstraint (@ NotNull PhpClass phpClass ) {
48+ if (!PhpElementsUtil .isInstanceOf (phpClass , "\\ Symfony\\ Component\\ Validator\\ Constraint" )) {
49+ return false ;
50+ }
51+
52+ // class in same namespace
53+ // @TODO: validateBy alias
54+ String className = phpClass .getFQN () + "Validator" ;
55+ return PhpElementsUtil .getClassesInterface (phpClass .getProject (), className ).size () > 0 ;
56+ }
57+
4958 private boolean isEntityRepository (@ NotNull PhpClass phpClass ) {
5059 return PhpElementsUtil .isInstanceOf (phpClass , "\\ Doctrine\\ ORM\\ EntityRepository" )
5160 && DoctrineMetadataUtil .findMetadataForRepositoryClass (phpClass ).size () > 0 ;
Original file line number Diff line number Diff line change @@ -157,6 +157,16 @@ public void testEntityRepositoryInsideDoctrineMetadataIsMarkedAsUsed() {
157157 assertTrue (new SymfonyImplicitUsageProvider ().isImplicitUsage (firstClassFromFile ));
158158 }
159159
160+ public void testConstraintValidatorReferenceIsMarkedAsUsed () {
161+ PsiFile psiFile = myFixture .configureByText (PhpFileType .INSTANCE , "<?php\n " +
162+ "namespace App\\ Validator;\n " +
163+ "class MyFoobarConstraint extends \\ Symfony\\ Component\\ Validator\\ Constraint {}\n "
164+ );
165+
166+ PhpClass firstClassFromFile = PhpElementsUtil .getFirstClassFromFile ((PhpFile ) psiFile .getContainingFile ());
167+ assertTrue (new SymfonyImplicitUsageProvider ().isImplicitUsage (firstClassFromFile ));
168+ }
169+
160170 public void testEventSubscriberGetSubscribedEventsArray () {
161171 PsiFile psiFile = myFixture .configureByText (PhpFileType .INSTANCE , "<?php\n " +
162172 "<?php\n " +
Original file line number Diff line number Diff line change @@ -64,3 +64,20 @@ class FooEntity
6464 }
6565}
6666
67+ namespace Symfony \Component \Validator
68+ {
69+ abstract class Constraint
70+ {
71+ }
72+ interface ConstraintValidatorInterface
73+ {
74+ }
75+ }
76+
77+ namespace App \Validator
78+ {
79+ use Symfony \Component \Validator \Constraint ;
80+
81+ class MyFoobarConstraintValidator extends Constraint {}
82+ }
83+
You can’t perform that action at this time.
0 commit comments