Search in sources :

Example 1 with MappingNode

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));
        }
    });
}
Also used : MappingNode(org.yaml.snakeyaml.nodes.MappingNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node)

Example 2 with MappingNode

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;
}
Also used : MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode)

Example 3 with MappingNode

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;
}
Also used : Position(org.eclipse.jface.text.Position) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) ArrayList(java.util.ArrayList) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

MappingNode (org.yaml.snakeyaml.nodes.MappingNode)3 Node (org.yaml.snakeyaml.nodes.Node)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Position (org.eclipse.jface.text.Position)1 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)1 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)1