use of org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation in project sts4 by spring-projects.
the class WebfluxHandlerCodeLensProvider method provideCodeLens.
protected void provideCodeLens(MethodDeclaration node, TextDocument document, List<CodeLens> resultAccumulator) {
IMethodBinding methodBinding = node.resolveBinding();
if (methodBinding != null && methodBinding.getDeclaringClass() != null && methodBinding.getMethodDeclaration() != null && methodBinding.getDeclaringClass().getBinaryName() != null && methodBinding.getMethodDeclaration().toString() != null) {
final String handlerClass = methodBinding.getDeclaringClass().getBinaryName().trim();
final String handlerMethod = methodBinding.getMethodDeclaration().toString().trim();
List<SymbolAddOnInformation> handlerInfos = this.springIndexer.getAllAdditionalInformation((addon) -> {
if (addon instanceof WebfluxHandlerInformation) {
WebfluxHandlerInformation handlerInfo = (WebfluxHandlerInformation) addon;
return handlerInfo.getHandlerClass() != null && handlerInfo.getHandlerClass().equals(handlerClass) && handlerInfo.getHandlerMethod() != null && handlerInfo.getHandlerMethod().equals(handlerMethod);
}
return false;
});
if (handlerInfos != null && handlerInfos.size() > 0) {
for (Object object : handlerInfos) {
try {
WebfluxHandlerInformation handlerInfo = (WebfluxHandlerInformation) object;
CodeLens codeLens = new CodeLens();
codeLens.setRange(document.toRange(node.getName().getStartPosition(), node.getName().getLength()));
String httpMethod = WebfluxUtils.getStringRep(handlerInfo.getHttpMethods(), string -> string);
String codeLensCommand = httpMethod != null ? httpMethod + " " : "";
codeLensCommand += handlerInfo.getPath();
String acceptType = WebfluxUtils.getStringRep(handlerInfo.getAcceptTypes(), WebfluxUtils::getMediaType);
codeLensCommand += acceptType != null ? " - Accept: " + acceptType : "";
String contentType = WebfluxUtils.getStringRep(handlerInfo.getContentTypes(), WebfluxUtils::getMediaType);
codeLensCommand += contentType != null ? " - Content-Type: " + contentType : "";
codeLens.setCommand(new Command(codeLensCommand, null));
resultAccumulator.add(codeLens);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
}
}
Aggregations