Skip to content

Commit c0e4b3b

Browse files
committed
PhpIndexUtil: fixed recursion [fixes #17]
1 parent 540fa34 commit c0e4b3b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/cz/juzna/intellij/nette/utils/PhpIndexUtil.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import java.util.ArrayList;
1111
import java.util.Collection;
12+
import java.util.HashSet;
1213

1314
public 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

Comments
 (0)