GH-1463: support concatenated strings while extracting request mapping path information
This commit is contained in:
@@ -224,12 +224,14 @@ public class ASTUtils {
|
||||
else if (exp instanceof SimpleName) {
|
||||
return ((SimpleName) exp).getIdentifier();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
Object constValue = exp.resolveConstantExpressionValue();
|
||||
if (constValue != null) {
|
||||
return constValue.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -383,6 +383,20 @@ public class RequestMappingSymbolProviderTest {
|
||||
assertTrue(containsSymbol(symbols, "@/produce3 - Content-Type: text/plain,testproducetype", docUri, 33, 1, 33, 94));
|
||||
assertTrue(containsSymbol(symbols, "@/everything - Accept: application/json,text/plain,testconsume - Content-Type: application/json", docUri, 38, 1, 38, 170));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPathWithConcatenatedString() throws Exception {
|
||||
String docUri = directory.toPath().resolve("src/main/java/org/test/MappingsWithConcatenatedStrings.java").toUri().toString();
|
||||
List<? extends WorkspaceSymbol> symbols = indexer.getSymbols(docUri);
|
||||
assertTrue(containsSymbol(symbols, "@/path1/path2 -- GET", docUri, 13, 1, 13, 33));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPathWithConcatenatedStringAndConstantInvolved() throws Exception {
|
||||
String docUri = directory.toPath().resolve("src/main/java/org/test/MappingsWithConcatenatedStrings.java").toUri().toString();
|
||||
List<? extends WorkspaceSymbol> symbols = indexer.getSymbols(docUri);
|
||||
assertTrue(containsSymbol(symbols, "@/path1/path/from/constant -- GET", docUri, 17, 1, 17, 56));
|
||||
}
|
||||
|
||||
private boolean containsSymbol(List<? extends WorkspaceSymbol> symbols, String name, String uri, int startLine, int startCHaracter, int endLine, int endCharacter) {
|
||||
for (Iterator<? extends WorkspaceSymbol> iterator = symbols.iterator(); iterator.hasNext();) {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.test;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import static org.springframework.web.bind.annotation.RequestMethod.PUT;
|
||||
|
||||
public class MappingsWithConcatenatedStrings {
|
||||
|
||||
@GetMapping("/path1" + "/path2")
|
||||
public void concatenatedPathMapping() {
|
||||
}
|
||||
|
||||
@GetMapping("/path1/" + Constants.REQUEST_MAPPING_PATH)
|
||||
public void concatenatedPathMappingWithConstant() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user