Skip to content

Commit 3df5d8e

Browse files
BoykoAlexmartinlippert
authored andcommitted
Polish up
Signed-off-by: aboyko <[email protected]>
1 parent 74ab2e2 commit 3df5d8e

File tree

8 files changed

+35
-48
lines changed

8 files changed

+35
-48
lines changed

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
package org.springframework.ide.vscode.boot.java.beans;
1212

1313
import java.util.Collection;
14-
import java.util.HashSet;
1514
import java.util.List;
1615
import java.util.Set;
1716

@@ -78,8 +77,7 @@ public static void indexBeanMethod(SpringIndexElement parentNode, Annotation nod
7877

7978
InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(method, doc);
8079

81-
Set<String> supertypes = new HashSet<>();
82-
ASTUtils.findSupertypes(beanType, supertypes);
80+
Set<String> supertypes = ASTUtils.findSupertypes(beanType);
8381

8482
Collection<Annotation> annotationsOnMethod = ASTUtils.getAnnotations(method);
8583
AnnotationMetadata[] annotations = ASTUtils.getAnnotationsMetadata(annotationsOnMethod, doc);

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
package org.springframework.ide.vscode.boot.java.beans;
1212

1313
import java.util.Collection;
14-
import java.util.HashSet;
1514
import java.util.Set;
1615

1716
import org.eclipse.jdt.core.dom.ASTNode;
@@ -101,8 +100,7 @@ private void indexFunctionBeans(TypeDeclaration typeDeclaration, SpringIndexerJa
101100
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
102101

103102
ITypeBinding concreteBeanType = typeDeclaration.resolveBinding();
104-
Set<String> supertypes = new HashSet<>();
105-
ASTUtils.findSupertypes(concreteBeanType, supertypes);
103+
Set<String> supertypes = ASTUtils.findSupertypes(concreteBeanType);
106104

107105
Collection<Annotation> annotationsOnTypeDeclaration = ASTUtils.getAnnotations(typeDeclaration);
108106
AnnotationMetadata[] annotations = ASTUtils.getAnnotationsMetadata(annotationsOnTypeDeclaration, doc);

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

+4-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.ArrayList;
1414
import java.util.Arrays;
1515
import java.util.Collection;
16-
import java.util.HashSet;
1716
import java.util.List;
1817
import java.util.Set;
1918
import java.util.stream.Collectors;
@@ -113,8 +112,7 @@ private void createSymbol(TypeDeclaration type, Annotation node, ITypeBinding an
113112

114113
InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(type, doc);
115114

116-
Set<String> supertypes = new HashSet<>();
117-
ASTUtils.findSupertypes(beanType, supertypes);
115+
Set<String> supertypes = ASTUtils.findSupertypes(beanType);
118116

119117
Collection<Annotation> annotationsOnType = ASTUtils.getAnnotations(type);
120118

@@ -176,8 +174,7 @@ private void createSymbol(RecordDeclaration record, Annotation node, ITypeBindin
176174

177175
InjectionPoint[] injectionPoints = DefaultValues.EMPTY_INJECTION_POINTS;
178176

179-
Set<String> supertypes = new HashSet<>();
180-
ASTUtils.findSupertypes(beanType, supertypes);
177+
Set<String> supertypes = ASTUtils.findSupertypes(beanType);
181178

182179
Collection<Annotation> annotationsOnType = ASTUtils.getAnnotations(record);
183180

@@ -321,8 +318,7 @@ public boolean visit(MethodInvocation methodInvocation) {
321318
Location location;
322319
location = new Location(doc.getUri(), nodeRegion.asRange());
323320

324-
Set<String> typesFromhierarchy = new HashSet<>();
325-
ASTUtils.findSupertypes(eventTypeBinding, typesFromhierarchy);
321+
Set<String> typesFromhierarchy = ASTUtils.findSupertypes(eventTypeBinding);
326322

327323
EventPublisherIndexElement eventPublisherIndexElement = new EventPublisherIndexElement(eventTypeBinding.getQualifiedName(), location, typesFromhierarchy);
328324
component.addChild(eventPublisherIndexElement);
@@ -593,8 +589,7 @@ public void createBean(SpringIndexElement parentNode, String beanName, String be
593589
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
594590

595591
InjectionPoint[] injectionPoints = DefaultValues.EMPTY_INJECTION_POINTS;
596-
Set<String> supertypes = new HashSet<>();
597-
ASTUtils.findSupertypes(beanTypeBinding, supertypes);
592+
Set<String> supertypes = ASTUtils.findSupertypes(beanTypeBinding);
598593

599594
AnnotationMetadata[] annotations = DefaultValues.EMPTY_ANNOTATIONS;
600595

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import java.util.Arrays;
1414
import java.util.Collection;
15-
import java.util.HashSet;
1615
import java.util.List;
1716
import java.util.Optional;
1817
import java.util.Set;
@@ -96,8 +95,7 @@ protected void createSymbolForType(AbstractTypeDeclaration type, Annotation node
9695

9796
InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(type, doc);
9897

99-
Set<String> supertypes = new HashSet<>();
100-
ASTUtils.findSupertypes(typeBinding, supertypes);
98+
Set<String> supertypes = ASTUtils.findSupertypes(typeBinding);
10199

102100
Collection<Annotation> annotationsOnType = ASTUtils.getAnnotations(type);
103101

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import java.util.Arrays;
1414
import java.util.Collection;
15-
import java.util.HashSet;
1615
import java.util.Set;
1716
import java.util.stream.Collectors;
1817
import java.util.stream.Stream;
@@ -82,8 +81,7 @@ private Two<WorkspaceSymbol, Bean> createSymbol(Annotation node, ITypeBinding an
8281

8382
InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(type, doc);
8483

85-
Set<String> supertypes = new HashSet<>();
86-
ASTUtils.findSupertypes(beanType, supertypes);
84+
Set<String> supertypes = ASTUtils.findSupertypes(beanType);
8785

8886
Collection<Annotation> annotationsOnType = ASTUtils.getAnnotations(type);
8987

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import java.util.ArrayList;
1414
import java.util.Collection;
15-
import java.util.HashSet;
1615
import java.util.List;
1716
import java.util.Set;
1817

@@ -81,8 +80,7 @@ public void addSymbols(TypeDeclaration typeDeclaration, SpringIndexerJavaContext
8180

8281
ITypeBinding concreteBeanTypeBindung = typeDeclaration.resolveBinding();
8382

84-
Set<String> supertypes = new HashSet<>();
85-
ASTUtils.findSupertypes(concreteBeanTypeBindung, supertypes);
83+
Set<String> supertypes = ASTUtils.findSupertypes(concreteBeanTypeBindung);
8684

8785
String concreteRepoType = concreteBeanTypeBindung.getQualifiedName();
8886

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

+17-13
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public static boolean isAbstractClass(TypeDeclaration typeDeclaration) {
399399
}
400400

401401
public static ITypeBinding findInTypeHierarchy(ITypeBinding resolvedType, Set<String> typesToCheck) {
402-
for (Iterator<ITypeBinding> itr = getSuperTypesIterator(resolvedType); itr.hasNext();) {
402+
for (Iterator<ITypeBinding> itr = getHierarchyTypesBreadthFirstIterator(resolvedType); itr.hasNext();) {
403403
ITypeBinding b = itr.next();
404404
String fqn = b.isParameterizedType() ? b.getBinaryName() : b.getQualifiedName();
405405
if (typesToCheck.contains(fqn)) {
@@ -445,17 +445,22 @@ public static Optional<DocumentEdits> getImportsEdit(CompilationUnit cu, Collect
445445
// return result;
446446
// }
447447
//
448-
public static void findSupertypes(ITypeBinding binding, Set<String> supertypesCollector) {
449-
for (Iterator<String> itr = getSuperTypesFqNamesIterator(binding); itr.hasNext();) {
448+
/**
449+
* Returns only the super types without the type itself.
450+
* @param binding
451+
* @return
452+
*/
453+
public static Set<String> findSupertypes(ITypeBinding binding) {
454+
Set<String> supertypesCollector = new HashSet<>();
455+
for (Iterator<String> itr = getHierarchyTypesFqNamesBreadthFirstIterator(binding); itr.hasNext();) {
450456
supertypesCollector.add(itr.next());
451457
}
458+
supertypesCollector.remove(binding.isParameterizedType() ? binding.getBinaryName() : binding.getQualifiedName());
459+
return supertypesCollector;
452460
}
453461

454462
public static boolean isAnyTypeInHierarchy(ITypeBinding binding, Collection<String> typeFqns) {
455-
if (typeFqns.contains(binding.isParameterizedType() ? binding.getBinaryName() : binding.getQualifiedName())) {
456-
return true;
457-
}
458-
for (Iterator<String> itr = getSuperTypesFqNamesIterator(binding); itr.hasNext();) {
463+
for (Iterator<String> itr = getHierarchyTypesFqNamesBreadthFirstIterator(binding); itr.hasNext();) {
459464
String fqn = itr.next();
460465
if (typeFqns.contains(fqn)) {
461466
return true;
@@ -466,8 +471,7 @@ public static boolean isAnyTypeInHierarchy(ITypeBinding binding, Collection<Stri
466471

467472
public static boolean areAllTypesInHierarchy(ITypeBinding binding, Collection<String> typeFqns) {
468473
HashSet<String> notFound = new HashSet<>(typeFqns);
469-
notFound.remove(binding.isParameterizedType() ? binding.getBinaryName() : binding.getQualifiedName());
470-
for (Iterator<String> itr = getSuperTypesFqNamesIterator(binding); itr.hasNext() && !notFound.isEmpty();) {
474+
for (Iterator<String> itr = getHierarchyTypesFqNamesBreadthFirstIterator(binding); itr.hasNext() && !notFound.isEmpty();) {
471475
notFound.remove(itr.next());
472476
}
473477
return notFound.isEmpty();
@@ -484,9 +488,9 @@ private static void enqueueSuperTypes(Queue<ITypeBinding> q, ITypeBinding t) {
484488
}
485489
}
486490

487-
public static Iterator<ITypeBinding> getSuperTypesIterator(ITypeBinding binding) {
491+
public static Iterator<ITypeBinding> getHierarchyTypesBreadthFirstIterator(ITypeBinding binding) {
488492
final Queue<ITypeBinding> q = new ArrayDeque<>(10);
489-
enqueueSuperTypes(q, binding);
493+
q.add(binding);
490494
return new Iterator<ITypeBinding>() {
491495

492496
@Override
@@ -507,8 +511,8 @@ public ITypeBinding next() {
507511
};
508512
}
509513

510-
public static Iterator<String> getSuperTypesFqNamesIterator(ITypeBinding binding) {
511-
Iterator<ITypeBinding> itr = getSuperTypesIterator(binding);
514+
public static Iterator<String> getHierarchyTypesFqNamesBreadthFirstIterator(ITypeBinding binding) {
515+
Iterator<ITypeBinding> itr = getHierarchyTypesBreadthFirstIterator(binding);
512516
return new Iterator<String>() {
513517

514518
@Override

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

+9-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.nio.file.Path;
2222
import java.nio.file.Paths;
2323
import java.util.ArrayList;
24-
import java.util.HashSet;
2524
import java.util.Iterator;
2625
import java.util.List;
2726
import java.util.Set;
@@ -67,10 +66,10 @@ void tearDown() {
6766
@Test
6867
void testTypeHierarchyIteratorSimpleClass() throws Exception {
6968
runTestsAgainstTypeDeclaration(mySimpleMain, (type) -> {
70-
Iterator<ITypeBinding> iter = ASTUtils.getSuperTypesIterator(type.resolveBinding());
69+
Iterator<ITypeBinding> iter = ASTUtils.getHierarchyTypesBreadthFirstIterator(type.resolveBinding());
7170
assertNotNull(iter);
7271

73-
// assertEquals("test.MySimpleMain", iter.next().getQualifiedName());
72+
assertEquals("test.MySimpleMain", iter.next().getQualifiedName());
7473
assertEquals("java.lang.Object", iter.next().getQualifiedName());
7574
assertFalse(iter.hasNext());
7675
});
@@ -79,8 +78,7 @@ void testTypeHierarchyIteratorSimpleClass() throws Exception {
7978
@Test
8079
void testSupertypesForSimpleClass() throws Exception {
8180
runTestsAgainstTypeDeclaration(mySimpleMain, (type) -> {
82-
Set<String> supertypes = new HashSet<>();
83-
ASTUtils.findSupertypes(type.resolveBinding(), supertypes);
81+
Set<String> supertypes = ASTUtils.findSupertypes(type.resolveBinding());
8482

8583
assertEquals(1, supertypes.size());
8684
assertTrue(supertypes.contains("java.lang.Object"));
@@ -113,10 +111,10 @@ void testAreAllTypesInHierarchyForSimpleClass() throws Exception {
113111
@Test
114112
void testTypeHierarchyIteratorWithSuperclassesAndInterfaces() throws Exception {
115113
runTestsAgainstTypeDeclaration(myComponent, (type) -> {
116-
Iterator<ITypeBinding> iter = ASTUtils.getSuperTypesIterator(type.resolveBinding());
114+
Iterator<ITypeBinding> iter = ASTUtils.getHierarchyTypesBreadthFirstIterator(type.resolveBinding());
117115
assertNotNull(iter);
118116

119-
// assertEquals("test.MyComponent", iter.next().getQualifiedName());
117+
assertEquals("test.MyComponent", iter.next().getQualifiedName());
120118
assertEquals("test.MyInterface", iter.next().getQualifiedName());
121119
assertEquals("test.MySuperclass", iter.next().getQualifiedName());
122120
assertEquals("test.MySuperInterface", iter.next().getQualifiedName());
@@ -129,10 +127,10 @@ void testTypeHierarchyIteratorWithSuperclassesAndInterfaces() throws Exception {
129127
@Test
130128
void testTypeHierarchyIteratorWithFullyQualifiedTypeNames() throws Exception {
131129
runTestsAgainstTypeDeclaration(myComponent, (type) -> {
132-
Iterator<String> iter = ASTUtils.getSuperTypesFqNamesIterator(type.resolveBinding());
130+
Iterator<String> iter = ASTUtils.getHierarchyTypesFqNamesBreadthFirstIterator(type.resolveBinding());
133131
assertNotNull(iter);
134132

135-
// assertEquals("test.MyComponent", iter.next());
133+
assertEquals("test.MyComponent", iter.next());
136134
assertEquals("test.MyInterface", iter.next());
137135
assertEquals("test.MySuperclass", iter.next());
138136
assertEquals("test.MySuperInterface", iter.next());
@@ -191,10 +189,10 @@ public interface TestInterface {
191189
""");
192190

193191
runTestsAgainstTypeDeclaration(second, (type) -> {
194-
Iterator<String> iter = ASTUtils.getSuperTypesFqNamesIterator(type.resolveBinding());
192+
Iterator<String> iter = ASTUtils.getHierarchyTypesFqNamesBreadthFirstIterator(type.resolveBinding());
195193
assertNotNull(iter);
196194

197-
// assertEquals("test.Second", iter.next());
195+
assertEquals("test.Second", iter.next());
198196
assertEquals("test.TestInterface", iter.next());
199197
assertEquals("test.Start", iter.next());
200198
assertEquals("test.TestInterface", iter.next());

0 commit comments

Comments
 (0)