use of org.springframework.ide.vscode.commons.yaml.ast.YamlParser in project sts4 by spring-projects.
the class ValuePropertyReferencesProvider method findReferencesInYMLFile.
private List<Location> findReferencesInYMLFile(String filePath, String propertyKey) {
List<Location> foundLocations = new ArrayList<>();
try {
String fileContent = FileUtils.readFileToString(new File(filePath));
Yaml yaml = new Yaml();
YamlASTProvider parser = new YamlParser(yaml);
URI docURI = Paths.get(filePath).toUri();
TextDocument doc = new TextDocument(docURI.toString(), null);
doc.setText(fileContent);
YamlFileAST ast = parser.getAST(doc);
List<Node> nodes = ast.getNodes();
if (nodes != null && !nodes.isEmpty()) {
for (Node node : nodes) {
Node foundNode = findNode(node, "", propertyKey);
if (foundNode != null) {
Position start = new Position();
start.setLine(foundNode.getStartMark().getLine());
start.setCharacter(foundNode.getStartMark().getColumn());
Position end = new Position();
end.setLine(foundNode.getEndMark().getLine());
end.setCharacter(foundNode.getEndMark().getColumn());
Range range = new Range();
range.setStart(start);
range.setEnd(end);
Location location = new Location(docURI.toString(), range);
foundLocations.add(location);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return foundLocations;
}
Aggregations