GH-1461: including the type hierarchy of events when finding references from listeners to publishers

This commit is contained in:
Martin Lippert
2025-02-03 13:29:56 +01:00
parent d9e8a0cadc
commit 168637d5fa
2 changed files with 8 additions and 2 deletions

View File

@@ -73,7 +73,7 @@ public class EventReferenceProvider implements ReferenceProvider {
.flatMap(bean -> bean.getChildren().stream())
.filter(element -> element instanceof EventPublisherIndexElement)
.map(element -> (EventPublisherIndexElement) element)
.filter(publisher -> publisher.getEventType().equals(eventType))
.filter(publisher -> publisher.getEventType().equals(eventType) || publisher.getEventTypesFromHierarchy().contains(eventType))
.map(publisher -> publisher.getLocation())
.toList();

View File

@@ -84,12 +84,18 @@ public class EventsReferencesProviderTest {
}""", tempJavaDocUri);
List<? extends Location> references = editor.getReferences();
assertEquals(1, references.size());
assertEquals(2, references.size());
String expectedDefinitionUri1 = directory.toPath().resolve("src/main/java/com/example/events/demo/CustomEventPublisher.java").toUri().toString();
Location expectedLocation1 = new Location(expectedDefinitionUri1, new Range(new Position(15, 2), new Position(15, 48)));
assertTrue(references.contains(expectedLocation1));
// from type hierarchy of specialzed custom event
String expectedDefinitionUri2 = directory.toPath().resolve("src/main/java/com/example/events/demo/SpecializedCustomEventPublisher.java").toUri().toString();
Location expectedLocation2 = new Location(expectedDefinitionUri2, new Range(new Position(15, 2), new Position(15, 59)));
assertTrue(references.contains(expectedLocation2));
}
@Test