Search in sources :

Example 6 with EnhancedSymbolInformation

use of org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation in project sts4 by spring-projects.

the class RequestMappingSymbolProvider method getSymbols.

@Override
public Collection<EnhancedSymbolInformation> getSymbols(Annotation node, ITypeBinding annotationType, Collection<ITypeBinding> metaAnnotations, TextDocument doc) {
    if (node.getParent() instanceof MethodDeclaration) {
        try {
            Location location = new Location(doc.getUri(), doc.toRange(node.getStartPosition(), node.getLength()));
            String[] path = getPath(node);
            String[] parentPath = getParentPath(node);
            String[] methods = getMethod(node);
            String[] contentTypes = getContentTypes(node);
            String[] acceptTypes = getAcceptTypes(node);
            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;
                if (resultPath.endsWith("/")) {
                    resultPath = resultPath.substring(0, resultPath.length() - 1);
                }
                return resultPath.startsWith("/") ? resultPath : "/" + resultPath;
            })).map(p -> RouteUtils.createRouteSymbol(location, p, methods, contentTypes, acceptTypes, null)).collect(Collectors.toList());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : ASTNode(org.eclipse.jdt.core.dom.ASTNode) Arrays(java.util.Arrays) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) Iterator(java.util.Iterator) Collection(java.util.Collection) SymbolProvider(org.springframework.ide.vscode.boot.java.handlers.SymbolProvider) Annotations(org.springframework.ide.vscode.boot.java.Annotations) MemberValuePair(org.eclipse.jdt.core.dom.MemberValuePair) Collectors(java.util.stream.Collectors) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) ASTUtils(org.springframework.ide.vscode.boot.java.utils.ASTUtils) EnhancedSymbolInformation(org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Expression(org.eclipse.jdt.core.dom.Expression) Annotation(org.eclipse.jdt.core.dom.Annotation) Location(org.eclipse.lsp4j.Location) NormalAnnotation(org.eclipse.jdt.core.dom.NormalAnnotation) SingleMemberAnnotation(org.eclipse.jdt.core.dom.SingleMemberAnnotation) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) Objects(java.util.Objects) Location(org.eclipse.lsp4j.Location)

Example 7 with EnhancedSymbolInformation

use of org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation in project sts4 by spring-projects.

the class BeansSymbolProvider method getSymbols.

@Override
public Collection<EnhancedSymbolInformation> getSymbols(Annotation node, ITypeBinding annotationType, Collection<ITypeBinding> metaAnnotations, TextDocument doc) {
    if (isMethodAbstract(node))
        return null;
    ImmutableList.Builder<EnhancedSymbolInformation> symbols = ImmutableList.builder();
    boolean isFunction = isFunctionBean(node);
    String beanType = getBeanType(node);
    for (Tuple2<String, DocumentRegion> nameAndRegion : getBeanNames(node, doc)) {
        try {
            symbols.add(new EnhancedSymbolInformation(new SymbolInformation(beanLabel(isFunction, nameAndRegion.getT1(), beanType, "@Bean"), SymbolKind.Interface, new Location(doc.getUri(), doc.toRange(nameAndRegion.getT2()))), null));
        } catch (BadLocationException e) {
            Log.log(e);
        }
    }
    return symbols.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) EnhancedSymbolInformation(org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation) EnhancedSymbolInformation(org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException) Location(org.eclipse.lsp4j.Location)

Example 8 with EnhancedSymbolInformation

use of org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation in project sts4 by spring-projects.

the class WebfluxRouterSymbolProvider method getSymbolsForRouterFunction.

private Collection<EnhancedSymbolInformation> getSymbolsForRouterFunction(MethodDeclaration methodDeclaration, TextDocument doc) {
    List<EnhancedSymbolInformation> result = new ArrayList<>();
    Block body = methodDeclaration.getBody();
    body.accept(new ASTVisitor() {

        @Override
        public boolean visit(MethodInvocation node) {
            IMethodBinding methodBinding = node.resolveMethodBinding();
            if (WebfluxUtils.isRouteMethodInvocation(methodBinding)) {
                extractMappingSymbol(node, doc, result);
            }
            return super.visit(node);
        }
    });
    return result;
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ArrayList(java.util.ArrayList) Block(org.eclipse.jdt.core.dom.Block) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) EnhancedSymbolInformation(org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor)

Aggregations

EnhancedSymbolInformation (org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation)8 Location (org.eclipse.lsp4j.Location)6 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)6 ImmutableList (com.google.common.collect.ImmutableList)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)4 Collection (java.util.Collection)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Stream (java.util.stream.Stream)4 ASTVisitor (org.eclipse.jdt.core.dom.ASTVisitor)4 Annotation (org.eclipse.jdt.core.dom.Annotation)4 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)4 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)4 NormalAnnotation (org.eclipse.jdt.core.dom.NormalAnnotation)4 SingleMemberAnnotation (org.eclipse.jdt.core.dom.SingleMemberAnnotation)4 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)4 File (java.io.File)3 URI (java.net.URI)3 Files (java.nio.file.Files)3