support constant value extraction for request mapping symbols for constants from the same class than the request mapping
This commit is contained in:
@@ -192,6 +192,14 @@ public class ASTUtils {
|
||||
}
|
||||
return getExpressionValueAsString(((QualifiedName) exp).getName());
|
||||
} else if (exp instanceof SimpleName) {
|
||||
IBinding binding = ((SimpleName) exp).resolveBinding();
|
||||
if (binding != null && binding.getKind() == IBinding.VARIABLE) {
|
||||
IVariableBinding varBinding = (IVariableBinding) binding;
|
||||
Object constValue = varBinding.getConstantValue();
|
||||
if (constValue != null) {
|
||||
return constValue.toString();
|
||||
}
|
||||
}
|
||||
return ((SimpleName) exp).getIdentifier();
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -71,13 +71,21 @@ public class RequestMappingSymbolProviderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleRequestMappingSymbolFromConstant() throws Exception {
|
||||
String docUri = directory.toPath().resolve("src/main/java/org/test/SimpleMappingClassWithConstant.java").toUri().toString();
|
||||
public void testSimpleRequestMappingSymbolFromConstantInDifferentClass() throws Exception {
|
||||
String docUri = directory.toPath().resolve("src/main/java/org/test/SimpleMappingClassWithConstantInDifferentClass.java").toUri().toString();
|
||||
List<? extends SymbolInformation> symbols = indexer.getSymbols(docUri);
|
||||
assertEquals(1, symbols.size());
|
||||
assertTrue(containsSymbol(symbols, "@/path/from/constant", docUri, 6, 1, 6, 48));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleRequestMappingSymbolFromConstantInSameClass() throws Exception {
|
||||
String docUri = directory.toPath().resolve("src/main/java/org/test/SimpleMappingClassWithConstantInSameClass.java").toUri().toString();
|
||||
List<? extends SymbolInformation> symbols = indexer.getSymbols(docUri);
|
||||
assertEquals(1, symbols.size());
|
||||
assertTrue(containsSymbol(symbols, "@/request/mapping/path/from/same/class/constant", docUri, 8, 1, 8, 52));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParentRequestMappingSymbol() throws Exception {
|
||||
String docUri = directory.toPath().resolve("src/main/java/org/test/ParentMappingClass.java").toUri().toString();
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.test;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
public class SimpleMappingClassWithConstant {
|
||||
public class SimpleMappingClassWithConstantInDifferentClass {
|
||||
|
||||
@RequestMapping(Constants.REQUEST_MAPPING_PATH)
|
||||
public String hello() {
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.test;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
public class SimpleMappingClassWithConstantInSameClass {
|
||||
|
||||
private static final String REQUEST_MAPPING_PATH_IN_SAME_CLASS = "/request/mapping/path/from/same/class/constant";
|
||||
|
||||
@RequestMapping(REQUEST_MAPPING_PATH_IN_SAME_CLASS)
|
||||
public String hello() {
|
||||
return "Hello";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user