Skip to content

Commit 9a7e63c

Browse files
committed
Traversal excludes type itself. Is in hierarchy includes type itself
Signed-off-by: aboyko <alex.boyko@broadcom.com>
1 parent 27891e9 commit 9a7e63c

File tree

2 files changed

+22
-14
lines changed
  • headless-services/spring-boot-language-server/src

2 files changed

+22
-14
lines changed

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/ASTUtils.java

+17-9
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ public static void findSupertypes(ITypeBinding binding, Set<String> supertypesCo
452452
}
453453

454454
public static boolean isAnyTypeInHierarchy(ITypeBinding binding, Collection<String> typeFqns) {
455+
if (typeFqns.contains(binding.isParameterizedType() ? binding.getBinaryName() : binding.getQualifiedName())) {
456+
return true;
457+
}
455458
for (Iterator<String> itr = getSuperTypesFqNamesIterator(binding); itr.hasNext();) {
456459
String fqn = itr.next();
457460
if (typeFqns.contains(fqn)) {
@@ -463,15 +466,27 @@ public static boolean isAnyTypeInHierarchy(ITypeBinding binding, Collection<Stri
463466

464467
public static boolean areAllTypesInHierarchy(ITypeBinding binding, Collection<String> typeFqns) {
465468
HashSet<String> notFound = new HashSet<>(typeFqns);
469+
notFound.remove(binding.isParameterizedType() ? binding.getBinaryName() : binding.getQualifiedName());
466470
for (Iterator<String> itr = getSuperTypesFqNamesIterator(binding); itr.hasNext() && !notFound.isEmpty();) {
467471
notFound.remove(itr.next());
468472
}
469473
return notFound.isEmpty();
470474
}
471475

476+
private static void enqueueSuperTypes(Queue<ITypeBinding> q, ITypeBinding t) {
477+
for (ITypeBinding b : t.getInterfaces()) {
478+
if (b != null) {
479+
q.add(b);
480+
}
481+
}
482+
if (t.getSuperclass() != null) {
483+
q.add(t.getSuperclass());
484+
}
485+
}
486+
472487
public static Iterator<ITypeBinding> getSuperTypesIterator(ITypeBinding binding) {
473488
final Queue<ITypeBinding> q = new ArrayDeque<>(10);
474-
q.add(binding);
489+
enqueueSuperTypes(q, binding);
475490
return new Iterator<ITypeBinding>() {
476491

477492
@Override
@@ -485,14 +500,7 @@ public ITypeBinding next() {
485500
if (t == null) {
486501
throw new NoSuchElementException();
487502
}
488-
for (ITypeBinding b : t.getInterfaces()) {
489-
if (b != null) {
490-
q.add(b);
491-
}
492-
}
493-
if (t.getSuperclass() != null) {
494-
q.add(t.getSuperclass());
495-
}
503+
enqueueSuperTypes(q, t);
496504
return t;
497505
}
498506

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/utils/test/ASTUtilsTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void testTypeHierarchyIteratorSimpleClass() throws Exception {
7070
Iterator<ITypeBinding> iter = ASTUtils.getSuperTypesIterator(type.resolveBinding());
7171
assertNotNull(iter);
7272

73-
assertEquals("test.MySimpleMain", iter.next().getQualifiedName());
73+
// assertEquals("test.MySimpleMain", iter.next().getQualifiedName());
7474
assertEquals("java.lang.Object", iter.next().getQualifiedName());
7575
assertFalse(iter.hasNext());
7676
});
@@ -116,7 +116,7 @@ void testTypeHierarchyIteratorWithSuperclassesAndInterfaces() throws Exception {
116116
Iterator<ITypeBinding> iter = ASTUtils.getSuperTypesIterator(type.resolveBinding());
117117
assertNotNull(iter);
118118

119-
assertEquals("test.MyComponent", iter.next().getQualifiedName());
119+
// assertEquals("test.MyComponent", iter.next().getQualifiedName());
120120
assertEquals("test.MyInterface", iter.next().getQualifiedName());
121121
assertEquals("test.MySuperclass", iter.next().getQualifiedName());
122122
assertEquals("test.MySuperInterface", iter.next().getQualifiedName());
@@ -132,7 +132,7 @@ void testTypeHierarchyIteratorWithFullyQualifiedTypeNames() throws Exception {
132132
Iterator<String> iter = ASTUtils.getSuperTypesFqNamesIterator(type.resolveBinding());
133133
assertNotNull(iter);
134134

135-
assertEquals("test.MyComponent", iter.next());
135+
// assertEquals("test.MyComponent", iter.next());
136136
assertEquals("test.MyInterface", iter.next());
137137
assertEquals("test.MySuperclass", iter.next());
138138
assertEquals("test.MySuperInterface", iter.next());
@@ -194,10 +194,10 @@ public interface TestInterface {
194194
Iterator<String> iter = ASTUtils.getSuperTypesFqNamesIterator(type.resolveBinding());
195195
assertNotNull(iter);
196196

197-
assertEquals("test.Second", iter.next());
197+
// assertEquals("test.Second", iter.next());
198198
assertEquals("test.TestInterface", iter.next());
199199
assertEquals("test.Start", iter.next());
200-
// assertEquals("test.TestInterface", iter.next());
200+
assertEquals("test.TestInterface", iter.next());
201201
assertEquals("java.lang.Object", iter.next());
202202
assertFalse(iter.hasNext());
203203
});

0 commit comments

Comments
 (0)