use of org.yaml.snakeyaml.nodes.NodeTuple in project KaiZen-OpenAPI-Editor by RepreZen.
the class ValidationUtil method findNode.
/*
* Returns the yaml node that matches the given path.
*
* The path is given as a list of String. The Node matching the path is found by traversing the children of the node
* pass as first parameter.
*/
private static Node findNode(MappingNode root, List<String> paths) {
if (paths.isEmpty())
return root;
String path = paths.get(0);
if (path.startsWith("/")) {
path = path.substring(1, path.length());
}
final List<String> next = paths.subList(1, paths.size());
// ~1 is use to escape /
if (path.contains("~1")) {
path = path.replaceAll("~1", "/");
}
for (NodeTuple child : root.getValue()) {
if (child.getKeyNode() instanceof ScalarNode) {
ScalarNode scalar = (ScalarNode) child.getKeyNode();
if (scalar.getValue().equals(path)) {
return findNode(child, next);
}
}
}
return root;
}
use of org.yaml.snakeyaml.nodes.NodeTuple in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonReconcilingStrategy method calculatePositions.
protected List<Position> calculatePositions(MappingNode mapping) {
List<Position> positions = new ArrayList<>();
int start;
int end = -1;
for (NodeTuple tuple : mapping.getValue()) {
start = tuple.getKeyNode().getStartMark().getLine();
end = tuple.getValueNode().getEndMark().getLine();
if ((end - start) > 0) {
try {
int startOffset = document.getLineOffset(start);
int endOffset = document.getLineOffset(end);
positions.add(new Position(startOffset, (endOffset - startOffset)));
} catch (BadLocationException e) {
}
}
if (tuple.getValueNode() instanceof MappingNode) {
positions.addAll(calculatePositions((MappingNode) tuple.getValueNode()));
}
}
return positions;
}
Aggregations