Search in sources :

Example 16 with BadLocationException

use of org.springframework.ide.vscode.commons.util.BadLocationException in project sts4 by spring-projects.

the class WebfluxRouterSymbolProvider method extractPath.

private WebfluxRouteElement[] extractPath(MethodInvocation routerInvocation, TextDocument doc) {
    WebfluxPathFinder pathFinder = new WebfluxPathFinder(routerInvocation, doc);
    List<?> arguments = routerInvocation.arguments();
    for (Object argument : arguments) {
        if (argument != null && argument instanceof ASTNode) {
            ((ASTNode) argument).accept(pathFinder);
        }
    }
    List<WebfluxRouteElement> path = pathFinder.getPath();
    extractNestedValue(routerInvocation, path, (methodInvocation) -> {
        IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
        String methodName = methodBinding.getName();
        try {
            if (WebfluxUtils.REQUEST_PREDICATE_PATH_METHOD.equals(methodName)) {
                StringLiteral stringLiteral = WebfluxUtils.extractStringLiteralArgument(methodInvocation);
                if (stringLiteral != null) {
                    Range range = doc.toRange(stringLiteral.getStartPosition(), stringLiteral.getLength());
                    return new WebfluxRouteElement(stringLiteral.getLiteralValue(), range);
                }
            }
        } catch (BadLocationException e) {
        // ignore
        }
        return null;
    });
    return (WebfluxRouteElement[]) path.toArray(new WebfluxRouteElement[path.size()]);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) StringLiteral(org.eclipse.jdt.core.dom.StringLiteral) ASTNode(org.eclipse.jdt.core.dom.ASTNode) Range(org.eclipse.lsp4j.Range) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Example 17 with BadLocationException

use of org.springframework.ide.vscode.commons.util.BadLocationException in project sts4 by spring-projects.

the class WebfluxRouterSymbolProvider method extractMethods.

private WebfluxRouteElement[] extractMethods(MethodInvocation routerInvocation, TextDocument doc) {
    WebfluxMethodFinder methodFinder = new WebfluxMethodFinder(routerInvocation, doc);
    List<?> arguments = routerInvocation.arguments();
    for (Object argument : arguments) {
        if (argument != null && argument instanceof ASTNode) {
            ((ASTNode) argument).accept(methodFinder);
        }
    }
    final List<WebfluxRouteElement> methods = methodFinder.getMethods();
    extractNestedValue(routerInvocation, methods, (methodInvocation) -> {
        IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
        String methodName = methodBinding.getName();
        try {
            if (WebfluxUtils.REQUEST_PREDICATE_METHOD_METHOD.equals(methodName)) {
                QualifiedName qualifiedName = WebfluxUtils.extractQualifiedNameArgument(methodInvocation);
                if (qualifiedName.getName() != null) {
                    Range range = doc.toRange(qualifiedName.getStartPosition(), qualifiedName.getLength());
                    return new WebfluxRouteElement(qualifiedName.getName().toString(), range);
                }
            }
        } catch (BadLocationException e) {
        // ignore
        }
        return null;
    });
    return (WebfluxRouteElement[]) methods.toArray(new WebfluxRouteElement[methods.size()]);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) QualifiedName(org.eclipse.jdt.core.dom.QualifiedName) ASTNode(org.eclipse.jdt.core.dom.ASTNode) Range(org.eclipse.lsp4j.Range) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Example 18 with BadLocationException

use of org.springframework.ide.vscode.commons.util.BadLocationException in project sts4 by spring-projects.

the class WebfluxRouterSymbolProvider method extractAcceptTypes.

private WebfluxRouteElement[] extractAcceptTypes(MethodInvocation routerInvocation, TextDocument doc) {
    WebfluxAcceptTypeFinder typeFinder = new WebfluxAcceptTypeFinder(doc);
    List<?> arguments = routerInvocation.arguments();
    for (Object argument : arguments) {
        if (argument != null && argument instanceof ASTNode) {
            ((ASTNode) argument).accept(typeFinder);
        }
    }
    final List<WebfluxRouteElement> acceptTypes = typeFinder.getAcceptTypes();
    extractNestedValue(routerInvocation, acceptTypes, (methodInvocation) -> {
        IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
        String methodName = methodBinding.getName();
        try {
            if (WebfluxUtils.REQUEST_PREDICATE_ACCEPT_TYPE_METHOD.equals(methodName)) {
                SimpleName nameArgument = WebfluxUtils.extractSimpleNameArgument(methodInvocation);
                if (nameArgument != null && nameArgument.getFullyQualifiedName() != null) {
                    Range range = doc.toRange(nameArgument.getStartPosition(), nameArgument.getLength());
                    return new WebfluxRouteElement(nameArgument.getFullyQualifiedName().toString(), range);
                }
            }
        } catch (BadLocationException e) {
        // ignore
        }
        return null;
    });
    return (WebfluxRouteElement[]) acceptTypes.toArray(new WebfluxRouteElement[acceptTypes.size()]);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) SimpleName(org.eclipse.jdt.core.dom.SimpleName) ASTNode(org.eclipse.jdt.core.dom.ASTNode) Range(org.eclipse.lsp4j.Range) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Example 19 with BadLocationException

use of org.springframework.ide.vscode.commons.util.BadLocationException in project sts4 by spring-projects.

the class SimpleTextDocumentService method didChange.

@Override
public final void didChange(DidChangeTextDocumentParams params) {
    async.execute(() -> {
        try {
            VersionedTextDocumentIdentifier docId = params.getTextDocument();
            String url = docId.getUri();
            // Log.debug("didChange: "+url);
            if (url != null) {
                TextDocument doc = getDocument(url);
                List<TextDocumentContentChangeEvent> changes = params.getContentChanges();
                doc.apply(params);
                didChangeContent(doc, changes);
            }
        } catch (BadLocationException e) {
            Log.log(e);
        }
    });
}
Also used : VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) TextDocumentContentChangeEvent(org.eclipse.lsp4j.TextDocumentContentChangeEvent) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Example 20 with BadLocationException

use of org.springframework.ide.vscode.commons.util.BadLocationException in project sts4 by spring-projects.

the class YamlDocument method getLineIndentation.

/**
 * Returns the number of leading spaces in front of a line. If the line is effectively empty (only contains
 * comments and/or spaces then this returns -1 (meaning undefined, as indentation level only really means
 * something for lines which have 'real' content.
 */
public int getLineIndentation(int line) {
    IRegion r;
    try {
        r = getLineInformation(line);
    } catch (BadLocationException e) {
        // not a line in the document so it has no indentation
        return -1;
    }
    int len = r.getLength();
    int startOfLine = r.getOffset();
    int leadingSpaces = 0;
    while (leadingSpaces < len) {
        char c = getChar(startOfLine + leadingSpaces);
        if (c == ' ') {
            leadingSpaces++;
        } else if (c == '#') {
            return -1;
        } else if (c != ' ') {
            return leadingSpaces;
        }
        leadingSpaces++;
    }
    // Whole line scanned and nothing but spaces found
    return -1;
}
Also used : IRegion(org.springframework.ide.vscode.commons.util.text.IRegion) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Aggregations

BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)23 Range (org.eclipse.lsp4j.Range)10 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)9 Location (org.eclipse.lsp4j.Location)5 ASTNode (org.eclipse.jdt.core.dom.ASTNode)4 SimpleName (org.eclipse.jdt.core.dom.SimpleName)4 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)3 ImmutableList (com.google.common.collect.ImmutableList)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 QualifiedName (org.eclipse.jdt.core.dom.QualifiedName)2 StringLiteral (org.eclipse.jdt.core.dom.StringLiteral)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 File (java.io.File)1 Paths (java.nio.file.Paths)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1