Skip to content

Commit

Permalink
take qualified name nodes into account when identifying webflux routes
Browse files Browse the repository at this point in the history
Fixes GH-1447
  • Loading branch information
martinlippert committed Jan 15, 2025
1 parent 9bc2fa8 commit e2a8eae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Pivotal, Inc.
* Copyright (c) 2018, 2024 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -67,8 +67,11 @@ public static SimpleName extractSimpleNameArgument(MethodInvocation node) {
List<?> arguments = node.arguments();
if (arguments != null && arguments.size() > 0) {
Object object = arguments.get(0);
if (object instanceof SimpleName) {
return (SimpleName) object;
if (object instanceof SimpleName sn) {
return sn;
}
else if (object instanceof QualifiedName qn) {
return qn.getName();
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ void testRoutesMappingSymbols() throws Exception {
String docUri = directory.toPath().resolve("src/main/java/org/test/QuoteRouter.java").toUri().toString();
List<? extends WorkspaceSymbol> symbols = indexer.getSymbols(docUri);
assertEquals(6, symbols.size());
assertTrue(containsSymbol(symbols, "@/hello -- GET - Accept: text/plain", docUri, 22, 5, 22, 70));
assertTrue(containsSymbol(symbols, "@/echo -- POST - Accept: text/plain - Content-Type: text/plain", docUri, 23, 5, 23, 101));
assertTrue(containsSymbol(symbols, "@/quotes -- GET - Accept: application/json", docUri, 24, 5, 24, 86));
assertTrue(containsSymbol(symbols, "@/quotes -- GET - Accept: application/stream+json", docUri, 25, 5, 25, 94));
assertTrue(containsSymbol(symbols, "@/hello -- GET - Accept: text/plain", docUri, 23, 5, 23, 70));
assertTrue(containsSymbol(symbols, "@/echo -- POST - Accept: text/plain - Content-Type: text/plain", docUri, 24, 5, 24, 101));
assertTrue(containsSymbol(symbols, "@/quotes -- GET - Accept: application/json", docUri, 25, 5, 25, 86));
assertTrue(containsSymbol(symbols, "@/quotes -- GET - Accept: application/stream+json", docUri, 26, 5, 26, 122));

Bean[] routeBeans = springIndex.getBeansWithName(project.getElementName(), "route");
assertEquals(1, routeBeans.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;

import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_STREAM_JSON;
import static org.springframework.http.MediaType.TEXT_PLAIN;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
Expand All @@ -23,6 +24,6 @@ public RouterFunction<ServerResponse> route(QuoteHandler quoteHandler) {
.route(GET("/hello").and(accept(TEXT_PLAIN)), quoteHandler::hello)
.andRoute(POST("/echo").and(accept(TEXT_PLAIN).and(contentType(TEXT_PLAIN))), quoteHandler::echo)
.andRoute(GET("/quotes").and(accept(APPLICATION_JSON)), quoteHandler::fetchQuotes)
.andRoute(GET("/quotes").and(accept(APPLICATION_STREAM_JSON)), quoteHandler::streamQuotes);
.andRoute(RequestPredicates.GET("/quotes").and(accept(MediaType.APPLICATION_STREAM_JSON)), quoteHandler::streamQuotes);
}
}

0 comments on commit e2a8eae

Please sign in to comment.