Search in sources :

Example 1 with RequestMapping

use of org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping in project sts4 by spring-projects.

the class SpringBootApp method parseRequestMappingsJson.

public static Collection<RequestMapping> parseRequestMappingsJson(String json, String bootVersion) {
    JSONObject obj = new JSONObject(json);
    if (bootVersion.equals("2.x")) {
        return RequestMappingsParser20.parse(obj);
    } else {
        // 1.x
        List<RequestMapping> result = new ArrayList<>();
        Iterator<String> keys = obj.keys();
        while (keys.hasNext()) {
            String rawKey = keys.next();
            JSONObject value = obj.getJSONObject(rawKey);
            result.add(new Boot1xRequestMapping(rawKey, value));
        }
        return result;
    }
}
Also used : Boot1xRequestMapping(org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.Boot1xRequestMapping) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping) Boot1xRequestMapping(org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.Boot1xRequestMapping)

Example 2 with RequestMapping

use of org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping in project sts4 by spring-projects.

the class RequestMappingHoverProvider method methodMatchesAnnotation.

private boolean methodMatchesAnnotation(Annotation annotation, RequestMapping rm) {
    String rqClassName = rm.getFullyQualifiedClassName();
    if (rqClassName != null) {
        int chop = rqClassName.indexOf("$$EnhancerBySpringCGLIB$$");
        if (chop >= 0) {
            rqClassName = rqClassName.substring(0, chop);
        }
        rqClassName = rqClassName.replace('$', '.');
        ASTNode parent = annotation.getParent();
        if (parent instanceof MethodDeclaration) {
            MethodDeclaration methodDec = (MethodDeclaration) parent;
            IMethodBinding binding = methodDec.resolveBinding();
            return binding.getDeclaringClass().getQualifiedName().equals(rqClassName) && binding.getName().equals(rm.getMethodName()) && Arrays.equals(Arrays.stream(binding.getParameterTypes()).map(t -> t.getTypeDeclaration().getQualifiedName()).toArray(String[]::new), rm.getMethodParameters());
        // } else if (parent instanceof TypeDeclaration) {
        // TypeDeclaration typeDec = (TypeDeclaration) parent;
        // return typeDec.resolveBinding().getQualifiedName().equals(rqClassName);
        }
    }
    return false;
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) Arrays(java.util.Arrays) IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) RequestMapping(org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping) Tuples(reactor.util.function.Tuples) Tuple2(reactor.util.function.Tuple2) Range(org.eclipse.lsp4j.Range) Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) HoverProvider(org.springframework.ide.vscode.boot.java.handlers.HoverProvider) Annotation(org.eclipse.jdt.core.dom.Annotation) ImmutableList(com.google.common.collect.ImmutableList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) ASTNode(org.eclipse.jdt.core.dom.ASTNode) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException) Log(org.springframework.ide.vscode.commons.util.Log) LiveHoverUtils(org.springframework.ide.vscode.boot.java.livehover.LiveHoverUtils) Collection(java.util.Collection) MarkedString(org.eclipse.lsp4j.MarkedString) Renderables(org.springframework.ide.vscode.commons.util.Renderables) Collectors(java.util.stream.Collectors) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) List(java.util.List) Stream(java.util.stream.Stream) SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Renderable(org.springframework.ide.vscode.commons.util.Renderable) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) ASTNode(org.eclipse.jdt.core.dom.ASTNode) MarkedString(org.eclipse.lsp4j.MarkedString)

Example 3 with RequestMapping

use of org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping in project sts4 by spring-projects.

the class RequestMappingHoverProvider method addHoverContent.

private void addHoverContent(List<Tuple2<RequestMapping, SpringBootApp>> mappingMethods, List<Either<String, MarkedString>> hoverContent) throws Exception {
    for (int i = 0; i < mappingMethods.size(); i++) {
        Tuple2<RequestMapping, SpringBootApp> mappingMethod = mappingMethods.get(i);
        SpringBootApp app = mappingMethod.getT2();
        String port = mappingMethod.getT2().getPort();
        String host = mappingMethod.getT2().getHost();
        List<Renderable> renderableUrls = Arrays.stream(mappingMethod.getT1().getSplitPath()).flatMap(path -> {
            String url = UrlUtil.createUrl(host, port, path);
            StringBuilder builder = new StringBuilder();
            builder.append("[");
            builder.append(url);
            builder.append("]");
            builder.append("(");
            builder.append(url);
            builder.append(")");
            return Stream.of(Renderables.text(builder.toString()), Renderables.lineBreak());
        }).collect(Collectors.toList());
        // Remove the last line break
        renderableUrls.remove(renderableUrls.size() - 1);
        hoverContent.add(Either.forLeft(Renderables.concat(renderableUrls).toMarkdown()));
        hoverContent.add(Either.forLeft(LiveHoverUtils.niceAppName(app)));
        if (i < mappingMethods.size() - 1) {
            // Three dashes == line separator in Markdown
            hoverContent.add(Either.forLeft("---"));
        }
    }
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Arrays(java.util.Arrays) IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) RequestMapping(org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping) Tuples(reactor.util.function.Tuples) Tuple2(reactor.util.function.Tuple2) Range(org.eclipse.lsp4j.Range) Hover(org.eclipse.lsp4j.Hover) ArrayList(java.util.ArrayList) HoverProvider(org.springframework.ide.vscode.boot.java.handlers.HoverProvider) Annotation(org.eclipse.jdt.core.dom.Annotation) ImmutableList(com.google.common.collect.ImmutableList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) ASTNode(org.eclipse.jdt.core.dom.ASTNode) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException) Log(org.springframework.ide.vscode.commons.util.Log) LiveHoverUtils(org.springframework.ide.vscode.boot.java.livehover.LiveHoverUtils) Collection(java.util.Collection) MarkedString(org.eclipse.lsp4j.MarkedString) Renderables(org.springframework.ide.vscode.commons.util.Renderables) Collectors(java.util.stream.Collectors) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) List(java.util.List) Stream(java.util.stream.Stream) SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Renderable(org.springframework.ide.vscode.commons.util.Renderable) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) Renderable(org.springframework.ide.vscode.commons.util.Renderable) MarkedString(org.eclipse.lsp4j.MarkedString) RequestMapping(org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping)

Aggregations

ArrayList (java.util.ArrayList)3 RequestMapping (org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping)3 ImmutableList (com.google.common.collect.ImmutableList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 ASTNode (org.eclipse.jdt.core.dom.ASTNode)2 Annotation (org.eclipse.jdt.core.dom.Annotation)2 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)2 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)2 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)2 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)2 Hover (org.eclipse.lsp4j.Hover)2 MarkedString (org.eclipse.lsp4j.MarkedString)2 Range (org.eclipse.lsp4j.Range)2 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)2 HoverProvider (org.springframework.ide.vscode.boot.java.handlers.HoverProvider)2 LiveHoverUtils (org.springframework.ide.vscode.boot.java.livehover.LiveHoverUtils)2