Skip to content

Commit 12263df

Browse files
committed
GH-1600: added symbol and index support for web API version attributes
1 parent c2f55fa commit 12263df

File tree

20 files changed

+706
-30
lines changed

20 files changed

+706
-30
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
public class HttpExchangeIndexElement extends WebEndpointIndexElement {
1616

17-
public HttpExchangeIndexElement(String path, String[] httpMethods, String[] contentTypes, String[] acceptTypes, Range range, String symbolLabel) {
18-
super(path, httpMethods, contentTypes, acceptTypes, range, symbolLabel);
17+
public HttpExchangeIndexElement(String path, String[] httpMethods, String[] contentTypes, String[] acceptTypes, String version, Range range, String symbolLabel) {
18+
super(path, httpMethods, contentTypes, acceptTypes, version, range, symbolLabel);
1919
}
2020
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class HttpExchangeIndexer {
2727
private static final Set<String> ATTRIBUTE_NAME_METHOD = Set.of("method");
2828
private static final Set<String> ATTRIBUTE_NAME_ACCEPT = Set.of("accept");
2929
private static final Set<String> ATTRIBUTE_NAME_CONTENT_TYPE = Set.of("contentType");
30+
private static final Set<String> ATTRIBUTE_NAME_VERSION = Set.of("version");
3031

3132
private static final Map<String, String[]> METHOD_MAPPING = Map.of(
3233
Annotations.GET_EXCHANGE, new String[] { "GET" },
@@ -57,4 +58,9 @@ public static String[] getMethod(Annotation node, SpringIndexerJavaContext conte
5758
return WebEndpointIndexer.getMethod(node, context, ATTRIBUTE_NAME_METHOD, METHOD_MAPPING, Annotations.HTTP_EXCHANGE);
5859
}
5960

61+
public static String getVersion(Annotation node, SpringIndexerJavaContext context) {
62+
String[] versions = WebEndpointIndexer.getAttributeValues(node, context, ATTRIBUTE_NAME_VERSION, Annotations.SPRING_REQUEST_MAPPING);
63+
return versions != null && versions.length == 1 ? versions[0] : null;
64+
}
65+
6066
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public void addSymbols(Annotation node, ITypeBinding typeBinding, Collection<ITy
4444
String[] methods = HttpExchangeIndexer.getMethod(node, context);
4545
String[] contentTypes = HttpExchangeIndexer.getContentTypes(node, context);
4646
String[] acceptTypes = HttpExchangeIndexer.getAcceptTypes(node, context);
47-
47+
String version = HttpExchangeIndexer.getVersion(node, context);
48+
4849
Stream<String> stream = parentPath == null ? Stream.of("") : Arrays.stream(parentPath);
4950
stream.filter(Objects::nonNull)
5051
.flatMap(parent -> (path == null ? Stream.<String>empty() : Arrays.stream(path))
@@ -53,11 +54,13 @@ public void addSymbols(Annotation node, ITypeBinding typeBinding, Collection<ITy
5354
}))
5455
.forEach(p -> {
5556
// symbol
56-
WorkspaceSymbol symbol = RouteUtils.createRouteSymbol(location, p, methods, contentTypes, acceptTypes);
57+
WorkspaceSymbol symbol = RouteUtils.createRouteSymbol(location, p, methods, contentTypes, acceptTypes, version);
5758
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
5859

5960
// index element
60-
HttpExchangeIndexElement requestMappingIndexElement = new HttpExchangeIndexElement(p, methods, contentTypes, acceptTypes, location.getRange(), symbol.getName());
61+
HttpExchangeIndexElement requestMappingIndexElement =
62+
new HttpExchangeIndexElement(p, methods, contentTypes, acceptTypes, version, location.getRange(), symbol.getName());
63+
6164
context.getBeans().add(new CachedBean(doc.getUri(), requestMappingIndexElement));
6265
});
6366

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public class RequestMappingIndexElement extends WebEndpointIndexElement {
1616

1717
private String methodSignature;
1818

19-
public RequestMappingIndexElement(String path, String[] httpMethods, String[] contentTypes, String[] acceptTypes, Range range, String symbolLabel, String methodSignature) {
20-
super(path, httpMethods, contentTypes, acceptTypes, range, symbolLabel);
19+
public RequestMappingIndexElement(String path, String[] httpMethods, String[] contentTypes, String[] acceptTypes, String version, Range range, String symbolLabel, String methodSignature) {
20+
super(path, httpMethods, contentTypes, acceptTypes, version, range, symbolLabel);
2121
this.methodSignature = methodSignature;
2222
}
2323

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class RequestMappingIndexer {
4444
private static final Set<String> ATTRIBUTE_NAME_METHOD = Set.of("method");
4545
private static final Set<String> ATTRIBUTE_NAME_CONSUMES = Set.of("consumes");
4646
private static final Set<String> ATTRIBUTE_NAME_PRODUCES = Set.of("produces");
47+
private static final Set<String> ATTRIBUTE_NAME_VERSION = Set.of("version");
4748

4849
private static final Map<String, String[]> METHOD_MAPPING = Map.of(
4950
Annotations.SPRING_GET_MAPPING, new String[] { "GET" },
@@ -96,6 +97,7 @@ public static void indexRequestMapping(Bean controller, Annotation node, SpringI
9697
String[] methods = getMethod(node, context);
9798
String[] contentTypes = getContentTypes(node, context);
9899
String[] acceptTypes = getAcceptTypes(node, context);
100+
String version = getVersion(node, context);
99101

100102
Stream<String> stream = parentPath == null ? Stream.of("") : Arrays.stream(parentPath);
101103
stream.filter(Objects::nonNull)
@@ -105,10 +107,12 @@ public static void indexRequestMapping(Bean controller, Annotation node, SpringI
105107
}))
106108
.forEach(p -> {
107109
// symbol
108-
WorkspaceSymbol symbol = RouteUtils.createRouteSymbol(location, p, methods, contentTypes, acceptTypes);
110+
WorkspaceSymbol symbol = RouteUtils.createRouteSymbol(location, p, methods, contentTypes, acceptTypes, version);
109111

110112
// index element for request mapping
111-
RequestMappingIndexElement requestMappingIndexElement = new RequestMappingIndexElement(p, methods, contentTypes, acceptTypes, location.getRange(), symbol.getName(), methodSignature);
113+
RequestMappingIndexElement requestMappingIndexElement =
114+
new RequestMappingIndexElement(p, methods, contentTypes, acceptTypes, version, location.getRange(), symbol.getName(), methodSignature);
115+
112116
controller.addChild(requestMappingIndexElement);
113117
});
114118

@@ -138,4 +142,9 @@ public static String[] getMethod(Annotation node, SpringIndexerJavaContext conte
138142
return WebEndpointIndexer.getMethod(node, context, ATTRIBUTE_NAME_METHOD, METHOD_MAPPING, Annotations.SPRING_REQUEST_MAPPING);
139143
}
140144

145+
public static String getVersion(Annotation node, SpringIndexerJavaContext context) {
146+
String[] versions = WebEndpointIndexer.getAttributeValues(node, context, ATTRIBUTE_NAME_VERSION, Annotations.SPRING_REQUEST_MAPPING);
147+
return versions != null && versions.length == 1 ? versions[0] : null;
148+
}
149+
141150
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public void addSymbols(Annotation node, ITypeBinding annotationType, Collection<
4646
String[] methods = RequestMappingIndexer.getMethod(node, context);
4747
String[] contentTypes = RequestMappingIndexer.getContentTypes(node, context);
4848
String[] acceptTypes = RequestMappingIndexer.getAcceptTypes(node, context);
49+
String version = RequestMappingIndexer.getVersion(node, context);
4950

5051
Stream<String> stream = parentPath == null ? Stream.of("") : Arrays.stream(parentPath);
5152
stream.filter(Objects::nonNull)
@@ -55,7 +56,7 @@ public void addSymbols(Annotation node, ITypeBinding annotationType, Collection<
5556
}))
5657
.forEach(p -> {
5758
// symbol
58-
WorkspaceSymbol symbol = RouteUtils.createRouteSymbol(location, p, methods, contentTypes, acceptTypes);
59+
WorkspaceSymbol symbol = RouteUtils.createRouteSymbol(location, p, methods, contentTypes, acceptTypes, version);
5960
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
6061
});
6162

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
public class RouteUtils {
2222

2323
public static WorkspaceSymbol createRouteSymbol(Location location, String path,
24-
String[] httpMethods, String[] contentTypes, String[] acceptTypes) {
24+
String[] httpMethods, String[] contentTypes, String[] acceptTypes, String version) {
2525

2626
if (path != null && path.length() > 0) {
2727
String label = "@" + (path.startsWith("/") ? path : ("/" + path));
2828
label += (httpMethods == null || httpMethods.length == 0 ? "" : " -- " + WebfluxUtils.getStringRep(httpMethods, string -> string));
2929

30+
label += version != null ? " - Version: " + version : "";
31+
3032
String acceptType = WebfluxUtils.getStringRep(acceptTypes, WebfluxUtils::getMediaType);
3133
label += acceptType != null ? " - Accept: " + acceptType : "";
3234

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ public class WebEndpointIndexElement extends AbstractSpringIndexElement implemen
2222
private final String[] httpMethods;
2323
private final String[] contentTypes;
2424
private final String[] acceptTypes;
25+
private final String version;
2526
private final String symbolLabel;
2627
private final Range range;
2728

28-
public WebEndpointIndexElement(String path, String[] httpMethods, String[] contentTypes, String[] acceptTypes, Range range, String symbolLabel) {
29+
public WebEndpointIndexElement(String path, String[] httpMethods, String[] contentTypes, String[] acceptTypes, String version, Range range, String symbolLabel) {
2930
this.path = path;
3031
this.httpMethods = httpMethods;
3132
this.contentTypes = contentTypes;
3233
this.acceptTypes = acceptTypes;
34+
this.version = version;
3335
this.range = range;
3436
this.symbolLabel = symbolLabel;
3537
}
@@ -49,6 +51,10 @@ public String[] getContentTypes() {
4951
public String[] getAcceptTypes() {
5052
return acceptTypes;
5153
}
54+
55+
public String getVersion() {
56+
return version;
57+
}
5258

5359
@Override
5460
public DocumentSymbol getDocumentSymbol() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public class WebfluxHandlerMethodIndexElement extends RequestMappingIndexElement
1818
private final String handlerMethod;
1919

2020
public WebfluxHandlerMethodIndexElement(String handlerClass, String handlerMethod, String path, String[] httpMethods, String[] contentTypes, String[] acceptTypes,
21-
Range range, String symbolLabel) {
22-
super(path, httpMethods, contentTypes, acceptTypes, range, symbolLabel, null);
21+
String version, Range range, String symbolLabel) {
22+
super(path, httpMethods, contentTypes, acceptTypes, version, range, symbolLabel, null);
2323

2424
this.handlerClass = handlerClass;
2525
this.handlerMethod = handlerMethod;

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ protected static void extractMappingSymbol(Bean beanDefinition, MethodInvocation
107107
WebfluxRouteElement[] httpMethods = extractMethods(node, doc);
108108
WebfluxRouteElement[] contentTypes = extractContentTypes(node, doc);
109109
WebfluxRouteElement[] acceptTypes = extractAcceptTypes(node, doc);
110+
WebfluxRouteElement version = extractVersion(node, doc);
111+
112+
// TODO: version
110113

111114
int methodNameStart = node.getName().getStartPosition();
112115
int invocationStart = node.getStartPosition();
@@ -124,11 +127,11 @@ protected static void extractMappingSymbol(Bean beanDefinition, MethodInvocation
124127
Location location = new Location(doc.getUri(), doc.toRange(methodNameStart, node.getLength() - (methodNameStart - invocationStart)));
125128

126129
WorkspaceSymbol symbol = RouteUtils.createRouteSymbol(location, path, getElementStrings(httpMethods),
127-
getElementStrings(contentTypes), getElementStrings(acceptTypes));
130+
getElementStrings(contentTypes), getElementStrings(acceptTypes), null);
128131

129132
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
130133

131-
WebfluxHandlerMethodIndexElement handler = extractHandlerInformation(node, path, httpMethods, contentTypes, acceptTypes, location.getRange(), symbol.getName());
134+
WebfluxHandlerMethodIndexElement handler = extractHandlerInformation(node, path, httpMethods, contentTypes, acceptTypes, version, location.getRange(), symbol.getName());
132135
WebfluxRouteElementRangesIndexElement elements = extractElementsInformation(pathElements, httpMethods, contentTypes, acceptTypes);
133136

134137
if (handler != null) beanDefinition.addChild(handler);
@@ -140,6 +143,11 @@ protected static void extractMappingSymbol(Bean beanDefinition, MethodInvocation
140143
}
141144
}
142145

146+
private static WebfluxRouteElement extractVersion(MethodInvocation node, TextDocument doc) {
147+
// TODO Auto-generated method stub
148+
return null;
149+
}
150+
143151
private static WebfluxRouteElementRangesIndexElement extractElementsInformation(WebfluxRouteElement[] path, WebfluxRouteElement[] methods,
144152
WebfluxRouteElement[] contentTypes, WebfluxRouteElement[] acceptTypes) {
145153
List<Range> allRanges = new ArrayList<>();
@@ -317,7 +325,7 @@ private static void extractNestedValue(ASTNode node, Collection<WebfluxRouteElem
317325
}
318326

319327
private static WebfluxHandlerMethodIndexElement extractHandlerInformation(MethodInvocation node, String path, WebfluxRouteElement[] httpMethods,
320-
WebfluxRouteElement[] contentTypes, WebfluxRouteElement[] acceptTypes, Range range, String symbolLabel) {
328+
WebfluxRouteElement[] contentTypes, WebfluxRouteElement[] acceptTypes, WebfluxRouteElement version, Range range, String symbolLabel) {
321329

322330
List<?> arguments = node.arguments();
323331

@@ -335,7 +343,7 @@ private static WebfluxHandlerMethodIndexElement extractHandlerInformation(Method
335343
if (handlerMethod != null) handlerMethod = handlerMethod.trim();
336344

337345
return new WebfluxHandlerMethodIndexElement(handlerClass, handlerMethod, path, getElementStrings(httpMethods), getElementStrings(contentTypes),
338-
getElementStrings(acceptTypes), range, symbolLabel);
346+
getElementStrings(acceptTypes), version.getElement(), range, symbolLabel);
339347
}
340348
}
341349
}

0 commit comments

Comments
 (0)