Merge branch 'master' of github.com:spring-projects/sts4
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.beans;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@@ -37,13 +39,13 @@ public class BeansSymbolProvider implements SymbolProvider {
|
||||
private static final String FUNCTION_SUPPLIER_TYPE = Supplier.class.getName();
|
||||
|
||||
@Override
|
||||
public SymbolInformation getSymbol(Annotation node, TextDocument doc) {
|
||||
public Collection<SymbolInformation> getSymbols(Annotation node, TextDocument doc) {
|
||||
try {
|
||||
if (isFunctionBean(node)) {
|
||||
return createFunctionSymbol(node, doc);
|
||||
return Collections.singleton(createFunctionSymbol(node, doc));
|
||||
}
|
||||
else {
|
||||
return createRegularBeanSymbol(node, doc);
|
||||
return Collections.singleton(createRegularBeanSymbol(node, doc));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.beans;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.eclipse.jdt.core.dom.ASTNode;
|
||||
import org.eclipse.jdt.core.dom.Annotation;
|
||||
import org.eclipse.jdt.core.dom.TypeDeclaration;
|
||||
@@ -25,7 +28,7 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
public class ComponentSymbolProvider implements SymbolProvider {
|
||||
|
||||
@Override
|
||||
public SymbolInformation getSymbol(Annotation node, TextDocument doc) {
|
||||
public Collection<SymbolInformation> getSymbols(Annotation node, TextDocument doc) {
|
||||
try {
|
||||
StringBuilder symbolLabel = new StringBuilder();
|
||||
symbolLabel.append("@+ ");
|
||||
@@ -41,7 +44,7 @@ public class ComponentSymbolProvider implements SymbolProvider {
|
||||
|
||||
SymbolInformation symbol = new SymbolInformation(symbolLabel.toString(), SymbolKind.Interface,
|
||||
new Location(doc.getUri(), doc.toRange(node.getStartPosition(), node.getLength())));
|
||||
return symbol;
|
||||
return Collections.singleton(symbol);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.handlers;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.jdt.core.dom.Annotation;
|
||||
import org.eclipse.lsp4j.SymbolInformation;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
@@ -19,6 +21,6 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
*/
|
||||
public interface SymbolProvider {
|
||||
|
||||
SymbolInformation getSymbol(Annotation node, TextDocument doc);
|
||||
Collection<SymbolInformation> getSymbols(Annotation node, TextDocument doc);
|
||||
|
||||
}
|
||||
|
||||
@@ -10,16 +10,24 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.requestmapping;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.eclipse.jdt.core.dom.ASTNode;
|
||||
import org.eclipse.jdt.core.dom.Annotation;
|
||||
import org.eclipse.jdt.core.dom.ArrayInitializer;
|
||||
import org.eclipse.jdt.core.dom.Expression;
|
||||
import org.eclipse.jdt.core.dom.ITypeBinding;
|
||||
import org.eclipse.jdt.core.dom.MemberValuePair;
|
||||
import org.eclipse.jdt.core.dom.MethodDeclaration;
|
||||
import org.eclipse.jdt.core.dom.NormalAnnotation;
|
||||
import org.eclipse.jdt.core.dom.QualifiedName;
|
||||
import org.eclipse.jdt.core.dom.SimpleName;
|
||||
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
|
||||
import org.eclipse.jdt.core.dom.StringLiteral;
|
||||
import org.eclipse.jdt.core.dom.TypeDeclaration;
|
||||
@@ -35,34 +43,34 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
public class RequestMappingSymbolProvider implements SymbolProvider {
|
||||
|
||||
@Override
|
||||
public SymbolInformation getSymbol(Annotation node, TextDocument doc) {
|
||||
public Collection<SymbolInformation> getSymbols(Annotation node, TextDocument doc) {
|
||||
try {
|
||||
String path = getPath(node);
|
||||
String parentPath = getParentPath(node);
|
||||
String method = getMethod(node);
|
||||
Location location = new Location(doc.getUri(), doc.toRange(node.getStartPosition(), node.getLength()));
|
||||
String[] path = getPath(node);
|
||||
String[] parentPath = getParentPath(node);
|
||||
String[] method = getMethod(node);
|
||||
|
||||
if (path != null && parentPath != null) {
|
||||
String separator = !parentPath.endsWith("/") && !path.startsWith("/") ? "/" : "";
|
||||
path = parentPath + separator + path;
|
||||
}
|
||||
if (path != null && !path.startsWith("/")) {
|
||||
path = "/" + path;
|
||||
}
|
||||
String methodStr = method == null || method.length == 0 ? "(no method defined)" : String.join(",", method);
|
||||
|
||||
String symbolLabel = "@" + path + " -- " + method;
|
||||
|
||||
SymbolInformation symbol = new SymbolInformation(symbolLabel, SymbolKind.Interface,
|
||||
new Location(doc.getUri(), doc.toRange(node.getStartPosition(), node.getLength())));
|
||||
return symbol;
|
||||
}
|
||||
catch (Exception e) {
|
||||
return (parentPath == null ? Stream.of("") : Arrays.stream(parentPath)).filter(Objects::nonNull)
|
||||
.flatMap(parent -> (path == null ? Stream.<String>empty() : Arrays.stream(path))
|
||||
.filter(Objects::nonNull).map(p -> {
|
||||
String separator = !parent.endsWith("/") && !p.startsWith("/") ? "/" : "";
|
||||
String resultPath = parent + separator + p;
|
||||
return resultPath.startsWith("/") ? resultPath : "/" + resultPath;
|
||||
}))
|
||||
.map(p -> "@" + p + " -- " + methodStr)
|
||||
.map(symbolLabel -> new SymbolInformation(symbolLabel, SymbolKind.Interface, location))
|
||||
.collect(Collectors.toList());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getMethod(Annotation node) {
|
||||
private String[] getMethod(Annotation node) {
|
||||
String[] methods = null;
|
||||
|
||||
if (node.isNormalAnnotation()) {
|
||||
NormalAnnotation normNode = (NormalAnnotation) node;
|
||||
List<?> values = normNode.values();
|
||||
@@ -73,25 +81,26 @@ public class RequestMappingSymbolProvider implements SymbolProvider {
|
||||
String valueName = pair.getName().getIdentifier();
|
||||
if (valueName != null && valueName.equals("method")) {
|
||||
Expression expression = pair.getValue();
|
||||
if (expression instanceof QualifiedName) {
|
||||
QualifiedName qualifiedName = (QualifiedName) expression;
|
||||
return qualifiedName.getName().toString();
|
||||
}
|
||||
methods = getExpressionValueAsArray(expression);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (node instanceof SingleMemberAnnotation) {
|
||||
methods = getRequestMethod((SingleMemberAnnotation)node);
|
||||
}
|
||||
|
||||
String type = node.getTypeName().toString();
|
||||
if (type != null && type.endsWith("Mapping") && !type.startsWith("Request")) {
|
||||
String method = type.substring(0, type.length() - 7).toUpperCase();
|
||||
return method;
|
||||
if (methods == null && node.getParent() instanceof MethodDeclaration) {
|
||||
Annotation parentAnnotation = getParentAnnotation(node);
|
||||
if (parentAnnotation != null) {
|
||||
methods = getMethod(parentAnnotation);
|
||||
}
|
||||
}
|
||||
|
||||
return "(no method defined)";
|
||||
return methods;
|
||||
}
|
||||
|
||||
private String getPath(Annotation node) {
|
||||
private String[] getPath(Annotation node) {
|
||||
if (node.isNormalAnnotation()) {
|
||||
NormalAnnotation normNode = (NormalAnnotation) node;
|
||||
List<?> values = normNode.values();
|
||||
@@ -102,26 +111,25 @@ public class RequestMappingSymbolProvider implements SymbolProvider {
|
||||
String valueName = pair.getName().getIdentifier();
|
||||
if (valueName != null && (valueName.equals("value") || valueName.equals("path"))) {
|
||||
Expression expression = pair.getValue();
|
||||
if (expression instanceof StringLiteral) {
|
||||
StringLiteral literal = (StringLiteral) expression;
|
||||
return literal.getLiteralValue();
|
||||
}
|
||||
return getExpressionValueAsArray(expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (node.isSingleMemberAnnotation()) {
|
||||
SingleMemberAnnotation singleNode = (SingleMemberAnnotation) node;
|
||||
Expression expression = singleNode.getValue();
|
||||
if (expression instanceof StringLiteral) {
|
||||
StringLiteral literal = (StringLiteral) expression;
|
||||
return literal.getLiteralValue();
|
||||
}
|
||||
return getExpressionValueAsArray(expression);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getParentPath(Annotation node) {
|
||||
private String[] getParentPath(Annotation node) {
|
||||
Annotation parentAnnotation = getParentAnnotation(node);
|
||||
return parentAnnotation == null ? null : getPath(parentAnnotation);
|
||||
}
|
||||
|
||||
private Annotation getParentAnnotation(Annotation node) {
|
||||
ASTNode parent = node.getParent() != null ? node.getParent().getParent() : null;
|
||||
while (parent != null && !(parent instanceof TypeDeclaration)) {
|
||||
parent = parent.getParent();
|
||||
@@ -138,7 +146,7 @@ public class RequestMappingSymbolProvider implements SymbolProvider {
|
||||
ITypeBinding resolvedType = annotation.resolveTypeBinding();
|
||||
String annotationType = resolvedType.getQualifiedName();
|
||||
if (annotationType != null && Constants.SPRING_REQUEST_MAPPING.equals(annotationType)) {
|
||||
return getPath(annotation);
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,4 +154,50 @@ public class RequestMappingSymbolProvider implements SymbolProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String[] getRequestMethod(SingleMemberAnnotation annotation) {
|
||||
ITypeBinding type = annotation.resolveTypeBinding();
|
||||
if (type != null) {
|
||||
switch (type.getQualifiedName()) {
|
||||
case Constants.SPRING_GET_MAPPING:
|
||||
return new String[] { "GET" };
|
||||
case Constants.SPRING_POST_MAPPING:
|
||||
return new String[] { "POST" };
|
||||
case Constants.SPRING_DELETE_MAPPING:
|
||||
return new String[] { "DELETE" };
|
||||
case Constants.SPRING_PUT_MAPPING:
|
||||
return new String[] { "PUT" };
|
||||
case Constants.SPRING_PATCH_MAPPING:
|
||||
return new String[] { "PATCH" };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getExpressionValueAsString(Expression exp) {
|
||||
if (exp instanceof StringLiteral) {
|
||||
return ((StringLiteral) exp).getLiteralValue();
|
||||
} else if (exp instanceof QualifiedName) {
|
||||
return getExpressionValueAsString(((QualifiedName) exp).getName());
|
||||
} else if (exp instanceof SimpleName) {
|
||||
return ((SimpleName) exp).getIdentifier();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static String[] getExpressionValueAsArray(Expression exp) {
|
||||
if (exp instanceof ArrayInitializer) {
|
||||
ArrayInitializer array = (ArrayInitializer) exp;
|
||||
return ((List<Expression>) array.expressions()).stream().map(e -> getExpressionValueAsString(e))
|
||||
.filter(Objects::nonNull).toArray(String[]::new);
|
||||
} else {
|
||||
String rm = getExpressionValueAsString(exp);
|
||||
if (rm != null) {
|
||||
return new String[] { rm };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -396,10 +397,12 @@ public class SpringIndexer {
|
||||
SymbolProvider provider = symbolProviders.get(qualifiedTypeName);
|
||||
if (provider != null) {
|
||||
TextDocument doc = getTempTextDocument(docURI, docRef, content);
|
||||
SymbolInformation symbol = provider.getSymbol(node, doc);
|
||||
if (symbol != null) {
|
||||
symbols.add(symbol);
|
||||
symbolsByDoc.computeIfAbsent(docURI, s -> new ArrayList<SymbolInformation>()).add(symbol);
|
||||
Collection<SymbolInformation> sbls = provider.getSymbols(node, doc);
|
||||
if (sbls != null) {
|
||||
sbls.forEach(symbol -> {
|
||||
symbols.add(symbol);
|
||||
symbolsByDoc.computeIfAbsent(docURI, s -> new ArrayList<SymbolInformation>()).add(symbol);
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -14,19 +14,12 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.lsp4j.SymbolInformation;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.SymbolProvider;
|
||||
import org.springframework.ide.vscode.boot.java.requestmapping.Constants;
|
||||
import org.springframework.ide.vscode.boot.java.requestmapping.RequestMappingSymbolProvider;
|
||||
import org.springframework.ide.vscode.boot.java.utils.SpringIndexer;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
|
||||
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
|
||||
@@ -35,29 +28,21 @@ import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
*/
|
||||
public class RequestMappingSymbolProviderTest {
|
||||
|
||||
private Map<String, SymbolProvider> symbolProviders;
|
||||
private BootLanguageServerHarness harness;
|
||||
private JavaProjectFinder projectFinder;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
symbolProviders = new HashMap<>();
|
||||
symbolProviders.put(Constants.SPRING_REQUEST_MAPPING, new RequestMappingSymbolProvider());
|
||||
|
||||
harness = BootLanguageServerHarness.builder().build();
|
||||
projectFinder = harness.getProjectFinder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleRequestMappingSymbol() throws Exception {
|
||||
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI()));
|
||||
|
||||
SpringIndexer indexer = new SpringIndexer(harness.getServer(), projectFinder, symbolProviders);
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI());
|
||||
indexer.initialize(directory.toPath());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = indexer.getSymbols(uriPrefix + "/src/main/java/org/test/SimpleMappingClass.java");
|
||||
List<? extends SymbolInformation> symbols = harness.getServer().getSpringIndexer().getSymbols(uriPrefix + "/src/main/java/org/test/SimpleMappingClass.java");
|
||||
assertEquals(1, symbols.size());
|
||||
assertTrue(containsSymbol(symbols, "@/greeting -- (no method defined)", uriPrefix + "/src/main/java/org/test/SimpleMappingClass.java", 6, 1, 6, 29));
|
||||
}
|
||||
@@ -66,14 +51,103 @@ public class RequestMappingSymbolProviderTest {
|
||||
public void testParentRequestMappingSymbol() throws Exception {
|
||||
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI()));
|
||||
|
||||
SpringIndexer indexer = new SpringIndexer(harness.getServer(), projectFinder, symbolProviders);
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI());
|
||||
indexer.initialize(directory.toPath());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = indexer.getSymbols(uriPrefix + "/src/main/java/org/test/ParentMappingClass.java");
|
||||
List<? extends SymbolInformation> symbols = harness.getServer().getSpringIndexer().getSymbols(uriPrefix + "/src/main/java/org/test/ParentMappingClass.java");
|
||||
assertEquals(2, symbols.size());
|
||||
assertTrue(containsSymbol(symbols, "@/parent/greeting -- (no method defined)", uriPrefix + "/src/main/java/org/test/ParentMappingClass.java", 7, 1, 7, 29));
|
||||
assertTrue(containsSymbol(symbols, "@/parent -- GET,POST,DELETE", uriPrefix + "/src/main/java/org/test/ParentMappingClass.java", 5, 0, 5, 58));
|
||||
assertTrue(containsSymbol(symbols, "@/parent/greeting -- GET", uriPrefix + "/src/main/java/org/test/ParentMappingClass.java", 8, 1, 8, 47));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiRequestMappingSymbol() throws Exception {
|
||||
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI()));
|
||||
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = harness.getServer().getSpringIndexer().getSymbols(uriPrefix + "/src/main/java/org/test/MultiRequestMappingClass.java");
|
||||
assertEquals(2, symbols.size());
|
||||
assertTrue(containsSymbol(symbols, "@/hello1 -- (no method defined)", uriPrefix + "/src/main/java/org/test/MultiRequestMappingClass.java", 6, 1, 6, 44));
|
||||
assertTrue(containsSymbol(symbols, "@/hello2 -- (no method defined)", uriPrefix + "/src/main/java/org/test/MultiRequestMappingClass.java", 6, 1, 6, 44));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMappingSymbol() throws Exception {
|
||||
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI()));
|
||||
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = harness.getServer().getSpringIndexer().getSymbols(uriPrefix + "/src/main/java/org/test/RequestMethodClass.java");
|
||||
assertTrue(containsSymbol(symbols, "@/getData -- GET", uriPrefix + "/src/main/java/org/test/RequestMethodClass.java", 12, 1, 12, 24));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMappingSymbol() throws Exception {
|
||||
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI()));
|
||||
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = harness.getServer().getSpringIndexer().getSymbols(uriPrefix + "/src/main/java/org/test/RequestMethodClass.java");
|
||||
assertTrue(containsSymbol(symbols, "@/deleteData -- DELETE", uriPrefix + "/src/main/java/org/test/RequestMethodClass.java", 20, 1, 20, 30));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostMappingSymbol() throws Exception {
|
||||
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI()));
|
||||
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = harness.getServer().getSpringIndexer().getSymbols(uriPrefix + "/src/main/java/org/test/RequestMethodClass.java");
|
||||
assertTrue(containsSymbol(symbols, "@/postData -- POST", uriPrefix + "/src/main/java/org/test/RequestMethodClass.java", 24, 1, 24, 26));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutMappingSymbol() throws Exception {
|
||||
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI()));
|
||||
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = harness.getServer().getSpringIndexer().getSymbols(uriPrefix + "/src/main/java/org/test/RequestMethodClass.java");
|
||||
assertTrue(containsSymbol(symbols, "@/putData -- PUT", uriPrefix + "/src/main/java/org/test/RequestMethodClass.java", 16, 1, 16, 24));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatchMappingSymbol() throws Exception {
|
||||
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI()));
|
||||
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = harness.getServer().getSpringIndexer().getSymbols(uriPrefix + "/src/main/java/org/test/RequestMethodClass.java");
|
||||
assertTrue(containsSymbol(symbols, "@/patchData -- PATCH", uriPrefix + "/src/main/java/org/test/RequestMethodClass.java", 28, 1, 28, 28));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRequestMappingSymbol() throws Exception {
|
||||
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI()));
|
||||
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = harness.getServer().getSpringIndexer().getSymbols(uriPrefix + "/src/main/java/org/test/RequestMethodClass.java");
|
||||
assertTrue(containsSymbol(symbols, "@/getHello -- GET", uriPrefix + "/src/main/java/org/test/RequestMethodClass.java", 32, 1, 32, 61));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiRequestMethodMappingSymbol() throws Exception {
|
||||
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI()));
|
||||
|
||||
File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-request-mapping-symbols/").toURI());
|
||||
|
||||
String uriPrefix = "file://" + directory.getAbsolutePath();
|
||||
List<? extends SymbolInformation> symbols = harness.getServer().getSpringIndexer().getSymbols(uriPrefix + "/src/main/java/org/test/RequestMethodClass.java");
|
||||
assertTrue(containsSymbol(symbols, "@/postAndPutHello -- POST,PUT", uriPrefix + "/src/main/java/org/test/RequestMethodClass.java", 36, 1, 36, 76));
|
||||
}
|
||||
|
||||
private boolean containsSymbol(List<? extends SymbolInformation> symbols, String name, String uri, int startLine, int startCHaracter, int endLine, int endCharacter) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.test;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
public class MultiRequestMappingClass {
|
||||
|
||||
@RequestMapping(path= {"/hello1","hello2"})
|
||||
public String hello() {
|
||||
return "Hello!!!";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package org.test;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod.*;
|
||||
|
||||
@RequestMapping("parent")
|
||||
@RequestMapping(value="parent", method= {GET,POST,DELETE})
|
||||
public class ParentMappingClass {
|
||||
|
||||
@RequestMapping("/greeting")
|
||||
@RequestMapping(value="/greeting", method=GET)
|
||||
public String hello() {
|
||||
return "Hello";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
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.*;
|
||||
|
||||
public class RequestMethodClass {
|
||||
|
||||
@GetMapping("/getData")
|
||||
public void getData() {
|
||||
}
|
||||
|
||||
@PutMapping("/putData")
|
||||
public void putData() {
|
||||
}
|
||||
|
||||
@DeleteMapping("/deleteData")
|
||||
public void deleteData() {
|
||||
}
|
||||
|
||||
@PostMapping("/postData")
|
||||
public void postData() {
|
||||
}
|
||||
|
||||
@PatchMapping("/patchData")
|
||||
public void patchData() {
|
||||
}
|
||||
|
||||
@RequestMapping(value="/getHello", method=RequestMethod.GET)
|
||||
public getHello() {
|
||||
}
|
||||
|
||||
@RequestMapping(path="/postAndPutHello", method= {RequestMethod.POST, PUT})
|
||||
public void updateHello() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user