use of org.springframework.ide.vscode.commons.util.BadLocationException in project sts4 by spring-projects.
the class ValuePropertyReferencesProvider method findReferencesInPropertiesFile.
private List<Location> findReferencesInPropertiesFile(String filePath, String propertyKey) {
List<Location> foundLocations = new ArrayList<>();
try {
String fileContent = FileUtils.readFileToString(new File(filePath));
Parser parser = new AntlrParser();
ParseResults parseResults = parser.parse(fileContent);
if (parseResults != null && parseResults.ast != null) {
parseResults.ast.getNodes(KeyValuePair.class).forEach(pair -> {
if (pair.getKey() != null && pair.getKey().decode().equals(propertyKey)) {
URI docURI = Paths.get(filePath).toUri();
TextDocument doc = new TextDocument(docURI.toString(), null);
doc.setText(fileContent);
try {
int line = doc.getLineOfOffset(pair.getKey().getOffset());
int startInLine = pair.getKey().getOffset() - doc.getLineOffset(line);
int endInLine = startInLine + (pair.getKey().getLength());
Position start = new Position();
start.setLine(line);
start.setCharacter(startInLine);
Position end = new Position();
end.setLine(line);
end.setCharacter(endInLine);
Range range = new Range();
range.setStart(start);
range.setEnd(end);
Location location = new Location(docURI.toString(), range);
foundLocations.add(location);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
return foundLocations;
}
use of org.springframework.ide.vscode.commons.util.BadLocationException in project sts4 by spring-projects.
the class WebfluxPathFinder method visit.
@Override
public boolean visit(MethodInvocation node) {
boolean visitChildren = true;
if (node != this.root) {
IMethodBinding methodBinding = node.resolveMethodBinding();
try {
if (WebfluxUtils.REQUEST_PREDICATES_TYPE.equals(methodBinding.getDeclaringClass().getBinaryName())) {
String name = methodBinding.getName();
if (name != null && WebfluxUtils.REQUEST_PREDICATE_ALL_PATH_METHODS.contains(name)) {
StringLiteral stringLiteral = WebfluxUtils.extractStringLiteralArgument(node);
if (stringLiteral != null) {
Range range = doc.toRange(stringLiteral.getStartPosition(), stringLiteral.getLength());
path.add(new WebfluxRouteElement(stringLiteral.getLiteralValue(), range));
}
}
}
} catch (BadLocationException e) {
// ignore
}
if (WebfluxUtils.isRouteMethodInvocation(methodBinding)) {
visitChildren = false;
}
}
return visitChildren;
}
use of org.springframework.ide.vscode.commons.util.BadLocationException in project sts4 by spring-projects.
the class WebfluxRouterSymbolProvider method extractContentTypes.
private WebfluxRouteElement[] extractContentTypes(MethodInvocation routerInvocation, TextDocument doc) {
WebfluxContentTypeFinder contentTypeFinder = new WebfluxContentTypeFinder(doc);
List<?> arguments = routerInvocation.arguments();
for (Object argument : arguments) {
if (argument != null && argument instanceof ASTNode) {
((ASTNode) argument).accept(contentTypeFinder);
}
}
final List<WebfluxRouteElement> contentTypes = contentTypeFinder.getContentTypes();
extractNestedValue(routerInvocation, contentTypes, (methodInvocation) -> {
IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
String methodName = methodBinding.getName();
try {
if (WebfluxUtils.REQUEST_PREDICATE_CONTENT_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[]) contentTypes.toArray(new WebfluxRouteElement[contentTypes.size()]);
}
use of org.springframework.ide.vscode.commons.util.BadLocationException in project sts4 by spring-projects.
the class WebfluxRouterSymbolProvider method extractMappingSymbol.
protected void extractMappingSymbol(MethodInvocation node, TextDocument doc, List<EnhancedSymbolInformation> result) {
WebfluxRouteElement[] pathElements = extractPath(node, doc);
WebfluxRouteElement[] httpMethods = extractMethods(node, doc);
WebfluxRouteElement[] contentTypes = extractContentTypes(node, doc);
WebfluxRouteElement[] acceptTypes = extractAcceptTypes(node, doc);
int methodNameStart = node.getName().getStartPosition();
int invocationStart = node.getStartPosition();
StringBuilder pathBuilder = new StringBuilder();
for (WebfluxRouteElement pathElement : pathElements) {
pathBuilder.insert(0, pathElement.getElement());
}
String path = pathBuilder.toString();
if (path.length() > 0) {
try {
Location location = new Location(doc.getUri(), doc.toRange(methodNameStart, node.getLength() - (methodNameStart - invocationStart)));
WebfluxHandlerInformation handler = extractHandlerInformation(node, path, httpMethods, contentTypes, acceptTypes);
WebfluxElementsInformation elements = extractElementsInformation(pathElements, httpMethods, contentTypes, acceptTypes);
result.add(RouteUtils.createRouteSymbol(location, path, getElementStrings(httpMethods), getElementStrings(contentTypes), getElementStrings(acceptTypes), new SymbolAddOnInformation[] { handler, elements }));
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
use of org.springframework.ide.vscode.commons.util.BadLocationException in project sts4 by spring-projects.
the class WebfluxContentTypeFinder method visit.
@Override
public boolean visit(MethodInvocation node) {
IMethodBinding methodBinding = node.resolveMethodBinding();
try {
if (WebfluxUtils.REQUEST_PREDICATES_TYPE.equals(methodBinding.getDeclaringClass().getBinaryName())) {
String name = methodBinding.getName();
if (name != null && WebfluxUtils.REQUEST_PREDICATE_CONTENT_TYPE_METHOD.equals(name)) {
SimpleName nameArgument = WebfluxUtils.extractSimpleNameArgument(node);
if (nameArgument != null && nameArgument.getFullyQualifiedName() != null) {
Range range = doc.toRange(nameArgument.getStartPosition(), nameArgument.getLength());
contentTypes.add(new WebfluxRouteElement(nameArgument.getFullyQualifiedName().toString(), range));
}
}
}
} catch (BadLocationException e) {
// ignore
}
return !WebfluxUtils.isRouteMethodInvocation(methodBinding);
}
Aggregations