99
1010import java .util .ArrayList ;
1111import java .util .Collection ;
12+ import java .util .HashSet ;
1213
1314public class PhpIndexUtil {
1415
@@ -17,10 +18,17 @@ public static Collection<PhpClass> getClasses(PhpType type, PhpIndex phpIndex) {
1718 }
1819
1920 public static Collection <PhpClass > getClasses (PhpType type , PhpIndex phpIndex , PhpClass containingClass ) {
21+ return getClasses (type , phpIndex , containingClass , new HashSet <String >());
22+ }
23+
24+ private static Collection <PhpClass > getClasses (PhpType type , PhpIndex phpIndex , PhpClass containingClass , Collection <String > recursionPrevention ) {
2025 Collection <PhpClass > classes = new ArrayList <PhpClass >();
2126 for (String className : type .getTypes ()) {
2227 if (className .startsWith ("#" )) {
23- classes .addAll (getBySignature (className , phpIndex ));
28+ if (!recursionPrevention .contains (className )) {
29+ recursionPrevention .add (className );
30+ classes .addAll (getBySignature (className , phpIndex , recursionPrevention ));
31+ }
2432 } else if (className .equals ("$this" )) {
2533 if (containingClass != null ) {
2634 classes .add (containingClass );
@@ -33,11 +41,11 @@ public static Collection<PhpClass> getClasses(PhpType type, PhpIndex phpIndex, P
3341 return classes ;
3442 }
3543
36- private static Collection <PhpClass > getBySignature (String sig , PhpIndex phpIndex ) {
44+ private static Collection <PhpClass > getBySignature (String sig , PhpIndex phpIndex , Collection < String > recursionPrevention ) {
3745
3846 Collection <PhpClass > classes = new ArrayList <PhpClass >();
3947 for (PhpNamedElement el : phpIndex .getBySignature (sig )) {
40- classes .addAll (getClasses (el .getType (), phpIndex , el instanceof PhpClassMember ? ((PhpClassMember ) el ).getContainingClass () : null ));
48+ classes .addAll (getClasses (el .getType (), phpIndex , el instanceof PhpClassMember ? ((PhpClassMember ) el ).getContainingClass () : null , recursionPrevention ));
4149 }
4250
4351 return classes ;
0 commit comments