Search in sources :

Example 6 with SymbolAddOnInformation

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();
                }
            }
        }
    }
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) CodeLens(org.eclipse.lsp4j.CodeLens) Command(org.eclipse.lsp4j.Command) SymbolAddOnInformation(org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Aggregations

SymbolAddOnInformation (org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 ASTParser (org.eclipse.jdt.core.dom.ASTParser)4 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)4 Location (org.eclipse.lsp4j.Location)4 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)4 EnhancedSymbolInformation (org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation)4 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)4 ImmutableList (com.google.common.collect.ImmutableList)3 File (java.io.File)3 URI (java.net.URI)3 Files (java.nio.file.Files)3 Path (java.nio.file.Path)3 Paths (java.nio.file.Paths)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3