Skip to content

Commit 1d0e76e

Browse files
committed
event listener index elements can now create corresponding document symbols
1 parent d5b21a7 commit 1d0e76e

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

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

+25-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
*******************************************************************************/
1111
package org.springframework.ide.vscode.boot.java.events;
1212

13+
import org.eclipse.lsp4j.DocumentSymbol;
1314
import org.eclipse.lsp4j.Location;
15+
import org.eclipse.lsp4j.SymbolKind;
1416
import org.springframework.ide.vscode.commons.protocol.spring.AbstractSpringIndexElement;
1517
import org.springframework.ide.vscode.commons.protocol.spring.AnnotationMetadata;
18+
import org.springframework.ide.vscode.commons.protocol.spring.SymbolElement;
1619

1720
/**
1821
* @author Martin Lippert
1922
*/
20-
public class EventListenerIndexElement extends AbstractSpringIndexElement {
23+
public class EventListenerIndexElement extends AbstractSpringIndexElement implements SymbolElement {
2124

2225
private final String eventType;
2326
private final Location location;
@@ -47,4 +50,25 @@ public String getContainerBeanType() {
4750
return containerBeanType;
4851
}
4952

53+
@Override
54+
public DocumentSymbol getDocumentSymbol() {
55+
DocumentSymbol symbol = new DocumentSymbol();
56+
symbol.setName("listens on: " + getSimpleType(eventType));
57+
symbol.setKind(SymbolKind.Event);
58+
symbol.setRange(location.getRange());
59+
symbol.setSelectionRange(location.getRange());
60+
61+
return symbol;
62+
}
63+
64+
private String getSimpleType(String fullyQualifiedType) {
65+
int index = fullyQualifiedType.lastIndexOf('.');
66+
if (index > 0 && index < fullyQualifiedType.length()) {
67+
return fullyQualifiedType.substring(index + 1);
68+
}
69+
else {
70+
return fullyQualifiedType;
71+
}
72+
}
73+
5074
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
import java.util.concurrent.CompletableFuture;
2424
import java.util.concurrent.TimeUnit;
2525

26+
import org.eclipse.lsp4j.DocumentSymbol;
2627
import org.eclipse.lsp4j.Location;
2728
import org.eclipse.lsp4j.Position;
2829
import org.eclipse.lsp4j.Range;
30+
import org.eclipse.lsp4j.SymbolKind;
2931
import org.eclipse.lsp4j.TextDocumentIdentifier;
3032
import org.junit.jupiter.api.BeforeEach;
3133
import org.junit.jupiter.api.Test;
@@ -125,6 +127,10 @@ void testAnnotationBasedEventListenerIndexElements() throws Exception {
125127
assertNotNull(location);
126128
assertEquals(docUri, location.getUri());
127129
assertEquals(new Range(new Position(10, 13), new Position(10, 24)), location.getRange());
130+
131+
DocumentSymbol symbol = listenerElement.getDocumentSymbol();
132+
assertEquals("listens on: ApplicationEvent", symbol.getName());
133+
assertEquals(SymbolKind.Event, symbol.getKind());
128134
}
129135

130136
@Test

0 commit comments

Comments
 (0)