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()]);
}
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()]);
}
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()]);
}
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);
}
});
}
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;
}
Aggregations