use of org.yaml.snakeyaml.nodes.MappingNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonReconcilingStrategy method calculatePositions.
protected void calculatePositions() {
if (!(document instanceof JsonDocument))
return;
final Node yaml = ((JsonDocument) document).getYaml();
if (!(yaml instanceof MappingNode)) {
return;
}
Display.getDefault().asyncExec(new Runnable() {
public void run() {
editor.updateFoldingStructure(calculatePositions((MappingNode) yaml));
}
});
}
use of org.yaml.snakeyaml.nodes.MappingNode in project KaiZen-OpenAPI-Editor by RepreZen.
the class ValidationUtil method getLine.
/*
* Returns the line for which an error message has been produced.
*
* The error message is a JSON object that contains the path to the invalid node. The path is accessible via
* instance.pointer. The path is in the forms: - /{id} - /{id}/~{nb} - /{id}/~{id2}
*
* The line number is computed by after parsing the yaml content with the yaml parser. This latter returns a tree of
* Node, each corresponding to a yaml construct and including a position.
*
* The Node matching the path is found by the methods findNode().
*/
public static int getLine(JsonNode error, Node yamlTree) {
String path = getInstancePointer(error);
if (path == null || path.isEmpty())
return 1;
path = path.substring(1, path.length());
String[] strings = path.split("/");
if (yamlTree instanceof MappingNode) {
MappingNode mn = (MappingNode) yamlTree;
Node findNode = findNode(mn, Arrays.asList(strings));
if (findNode != null) {
return findNode.getStartMark().getLine() + 1;
}
}
return 1;
}
use of org.yaml.snakeyaml.nodes.MappingNode 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