Skip to content

Commit e2a8eae

Browse files
committed
take qualified name nodes into account when identifying webflux routes
Fixes GH-1447
1 parent 9bc2fa8 commit e2a8eae

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018 Pivotal, Inc.
2+
* Copyright (c) 2018, 2024 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -67,8 +67,11 @@ public static SimpleName extractSimpleNameArgument(MethodInvocation node) {
6767
List<?> arguments = node.arguments();
6868
if (arguments != null && arguments.size() > 0) {
6969
Object object = arguments.get(0);
70-
if (object instanceof SimpleName) {
71-
return (SimpleName) object;
70+
if (object instanceof SimpleName sn) {
71+
return sn;
72+
}
73+
else if (object instanceof QualifiedName qn) {
74+
return qn.getName();
7275
}
7376
}
7477
return null;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ void testRoutesMappingSymbols() throws Exception {
8989
String docUri = directory.toPath().resolve("src/main/java/org/test/QuoteRouter.java").toUri().toString();
9090
List<? extends WorkspaceSymbol> symbols = indexer.getSymbols(docUri);
9191
assertEquals(6, symbols.size());
92-
assertTrue(containsSymbol(symbols, "@/hello -- GET - Accept: text/plain", docUri, 22, 5, 22, 70));
93-
assertTrue(containsSymbol(symbols, "@/echo -- POST - Accept: text/plain - Content-Type: text/plain", docUri, 23, 5, 23, 101));
94-
assertTrue(containsSymbol(symbols, "@/quotes -- GET - Accept: application/json", docUri, 24, 5, 24, 86));
95-
assertTrue(containsSymbol(symbols, "@/quotes -- GET - Accept: application/stream+json", docUri, 25, 5, 25, 94));
92+
assertTrue(containsSymbol(symbols, "@/hello -- GET - Accept: text/plain", docUri, 23, 5, 23, 70));
93+
assertTrue(containsSymbol(symbols, "@/echo -- POST - Accept: text/plain - Content-Type: text/plain", docUri, 24, 5, 24, 101));
94+
assertTrue(containsSymbol(symbols, "@/quotes -- GET - Accept: application/json", docUri, 25, 5, 25, 86));
95+
assertTrue(containsSymbol(symbols, "@/quotes -- GET - Accept: application/stream+json", docUri, 26, 5, 26, 122));
9696

9797
Bean[] routeBeans = springIndex.getBeansWithName(project.getElementName(), "route");
9898
assertEquals(1, routeBeans.length);

headless-services/spring-boot-language-server/src/test/resources/test-projects/test-webflux-project/src/main/java/org/test/QuoteRouter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import org.springframework.web.reactive.function.server.RouterFunction;
66
import org.springframework.web.reactive.function.server.RouterFunctions;
77
import org.springframework.web.reactive.function.server.ServerResponse;
8+
import org.springframework.http.MediaType;
9+
import org.springframework.web.reactive.function.server.RequestPredicates;
810

911
import static org.springframework.http.MediaType.APPLICATION_JSON;
10-
import static org.springframework.http.MediaType.APPLICATION_STREAM_JSON;
1112
import static org.springframework.http.MediaType.TEXT_PLAIN;
1213
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
1314
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
@@ -23,6 +24,6 @@ public RouterFunction<ServerResponse> route(QuoteHandler quoteHandler) {
2324
.route(GET("/hello").and(accept(TEXT_PLAIN)), quoteHandler::hello)
2425
.andRoute(POST("/echo").and(accept(TEXT_PLAIN).and(contentType(TEXT_PLAIN))), quoteHandler::echo)
2526
.andRoute(GET("/quotes").and(accept(APPLICATION_JSON)), quoteHandler::fetchQuotes)
26-
.andRoute(GET("/quotes").and(accept(APPLICATION_STREAM_JSON)), quoteHandler::streamQuotes);
27+
.andRoute(RequestPredicates.GET("/quotes").and(accept(MediaType.APPLICATION_STREAM_JSON)), quoteHandler::streamQuotes);
2728
}
2829
}

0 commit comments

Comments
 (0)