This commit is contained in:
aboyko
2025-04-04 16:56:51 -04:00
2 changed files with 31 additions and 1 deletions

View File

@@ -10,14 +10,17 @@
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.events;
import org.eclipse.lsp4j.DocumentSymbol;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.SymbolKind;
import org.springframework.ide.vscode.commons.protocol.spring.AbstractSpringIndexElement;
import org.springframework.ide.vscode.commons.protocol.spring.AnnotationMetadata;
import org.springframework.ide.vscode.commons.protocol.spring.SymbolElement;
/**
* @author Martin Lippert
*/
public class EventListenerIndexElement extends AbstractSpringIndexElement {
public class EventListenerIndexElement extends AbstractSpringIndexElement implements SymbolElement {
private final String eventType;
private final Location location;
@@ -47,4 +50,25 @@ public class EventListenerIndexElement extends AbstractSpringIndexElement {
return containerBeanType;
}
@Override
public DocumentSymbol getDocumentSymbol() {
DocumentSymbol symbol = new DocumentSymbol();
symbol.setName("listens on: " + getSimpleType(eventType));
symbol.setKind(SymbolKind.Event);
symbol.setRange(location.getRange());
symbol.setSelectionRange(location.getRange());
return symbol;
}
private String getSimpleType(String fullyQualifiedType) {
int index = fullyQualifiedType.lastIndexOf('.');
if (index > 0 && index < fullyQualifiedType.length()) {
return fullyQualifiedType.substring(index + 1);
}
else {
return fullyQualifiedType;
}
}
}

View File

@@ -23,9 +23,11 @@ import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.eclipse.lsp4j.DocumentSymbol;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.SymbolKind;
import org.eclipse.lsp4j.TextDocumentIdentifier;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -125,6 +127,10 @@ public class SpringIndexerEventsTest {
assertNotNull(location);
assertEquals(docUri, location.getUri());
assertEquals(new Range(new Position(10, 13), new Position(10, 24)), location.getRange());
DocumentSymbol symbol = listenerElement.getDocumentSymbol();
assertEquals("listens on: ApplicationEvent", symbol.getName());
assertEquals(SymbolKind.Event, symbol.getKind());
}
@Test