GH-1461: add event type hierarchy to publisher index element
This commit is contained in:
@@ -172,7 +172,10 @@ public class ComponentSymbolProvider extends AbstractSymbolProvider {
|
||||
Location location;
|
||||
location = new Location(doc.getUri(), nodeRegion.asRange());
|
||||
|
||||
EventPublisherIndexElement eventPublisherIndexElement = new EventPublisherIndexElement(eventTypeBinding.getQualifiedName(), location);
|
||||
Set<String> typesFromhierarchy = new HashSet<>();
|
||||
ASTUtils.findSupertypes(eventTypeBinding, typesFromhierarchy);
|
||||
|
||||
EventPublisherIndexElement eventPublisherIndexElement = new EventPublisherIndexElement(eventTypeBinding.getQualifiedName(), location, typesFromhierarchy);
|
||||
Bean publisherBeanElement = findBean(node, methodInvocation, context, doc);
|
||||
if (publisherBeanElement != null) {
|
||||
publisherBeanElement.addChild(eventPublisherIndexElement);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.events;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.lsp4j.Location;
|
||||
import org.springframework.ide.vscode.commons.protocol.spring.AbstractSpringIndexElement;
|
||||
|
||||
@@ -20,10 +22,12 @@ public class EventPublisherIndexElement extends AbstractSpringIndexElement {
|
||||
|
||||
private final String eventType;
|
||||
private final Location location;
|
||||
private final Set<String> eventTypesFromHierarchy;
|
||||
|
||||
public EventPublisherIndexElement(String eventType, Location location) {
|
||||
public EventPublisherIndexElement(String eventType, Location location, Set<String> eventTypesFromHierarchy) {
|
||||
this.eventType = eventType;
|
||||
this.location = location;
|
||||
this.eventTypesFromHierarchy = eventTypesFromHierarchy;
|
||||
}
|
||||
|
||||
public String getEventType() {
|
||||
@@ -34,4 +38,8 @@ public class EventPublisherIndexElement extends AbstractSpringIndexElement {
|
||||
return location;
|
||||
}
|
||||
|
||||
public Set<String> getEventTypesFromHierarchy() {
|
||||
return eventTypesFromHierarchy;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.events.test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -17,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -168,4 +170,24 @@ public class SpringIndexerEventsTest {
|
||||
assertEquals(new Range(new Position(15, 2), new Position(15, 48)), location.getRange());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEventPublisherWithEventTypeHierarchyIndexElements() throws Exception {
|
||||
String docUri = directory.toPath().resolve("src/main/java/com/example/events/demo/SpecializedCustomEventPublisher.java").toUri().toString();
|
||||
|
||||
Bean[] beans = springIndex.getBeansOfDocument(docUri);
|
||||
Bean listenerComponentBean = Arrays.stream(beans).filter(bean -> bean.getName().equals("specializedCustomEventPublisher")).findFirst().get();
|
||||
assertEquals("com.example.events.demo.SpecializedCustomEventPublisher", listenerComponentBean.getType());
|
||||
|
||||
List<SpringIndexElement> children = listenerComponentBean.getChildren();
|
||||
assertEquals(1, children.size());
|
||||
assertTrue(children.get(0) instanceof EventPublisherIndexElement);
|
||||
|
||||
EventPublisherIndexElement publisherElement = (EventPublisherIndexElement) children.get(0);
|
||||
assertEquals("com.example.events.demo.SpecializedCustomEvent", publisherElement.getEventType());
|
||||
Set<String> eventTypesFromHierarchy = publisherElement.getEventTypesFromHierarchy();
|
||||
assertTrue(eventTypesFromHierarchy.contains("com.example.events.demo.CustomEvent"));
|
||||
assertTrue(eventTypesFromHierarchy.contains("java.io.Serializable"));
|
||||
assertFalse(eventTypesFromHierarchy.contains("java.lang.String"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
package com.example.events.demo;
|
||||
|
||||
public class SpecializedCustomEvent extends CustomEvent {
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SpecializedCustomEvent extends CustomEvent implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6867577412741709537L;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user