private Construct getConstructor(Node node) { Class<?> cl = getClassForNode(node); node.setType(cl); // call the constructor as if the runtime class is defined Construct constructor = yamlClassConstructors.get(node.getNodeId()); return constructor; }
/** * Get the constructor to construct the Node. For implicit tags if the * runtime class is known a dedicated Construct implementation is used. * Otherwise the constructor is chosen by the tag. * * @param node {@link Node} to construct an instance from * @return {@link Construct} implementation for the specified node */ protected Construct getConstructor(Node node) { if (node.useClassConstructor()) { return yamlClassConstructors.get(node.getNodeId()); } else { Construct constructor = yamlConstructors.get(node.getTag()); if (constructor == null) { for (String prefix : yamlMultiConstructors.keySet()) { if (node.getTag().startsWith(prefix)) { return yamlMultiConstructors.get(prefix); } } return yamlConstructors.get(null); } return constructor; } }
if (node.getNodeId() == NodeId.sequence) { if (member != null) { if (t.equals(member.getClass())) if (childNode.getNodeId() == NodeId.mapping) { childNode.setTag(Tag.MAP); Node keyNode = tuple.getKeyNode(); if (t.equals(member.getClass())) { if (keyNode.getNodeId() == NodeId.mapping) { keyNode.setTag(Tag.MAP);
if (keyNode.getTag().equals(Tag.MERGE)) { iter.remove(); switch (valueNode.getNodeId()) { case mapping: MappingNode mn = (MappingNode) valueNode; node.getStartMark(), "expected a mapping for merging, but found " + subnode.getNodeId(), subnode.getStartMark()); node.getStartMark(), "expected a mapping or list of mappings for merging, but found " + valueNode.getNodeId(), valueNode.getStartMark());
if (!(node instanceof SequenceNode)) { throw new ConstructorException("while constructing an ordered map", node.getStartMark(), "expected a sequence, but found " + node.getNodeId(), node.getStartMark()); throw new ConstructorException("while constructing an ordered map", node.getStartMark(), "expected a mapping of length 1, but found " + subnode.getNodeId(), subnode.getStartMark());
NodeId nodeId = nodeValue.getNodeId(); if (customTag == null) { if (nodeId == NodeId.scalar) {
protected NodeId getNodeId(Node node) { NodeId id = node.getNodeId(); // if (id==NodeId.mapping && isMoustacheVar(node)) { // return NodeId.scalar; // } return id; }
private Node mergeNodes(Node baseNode, Node templateNode, MergeContext context) { if (baseNode.getNodeId() == mapping && templateNode.getNodeId() == mapping) { return mergeMappingNodes((MappingNode) baseNode, (MappingNode) templateNode, context); } if (templateNode.getNodeId() == mapping) { return cleanMergedTuples((MappingNode) templateNode, context); } return baseNode; }
private boolean expect(Node node, NodeId nodeId) { if (node.getNodeId() != nodeId) { addError(nodeId + " node expected", node); return false; } return true; }
/** * Retrieve String value of a scalar node. * @return String value or null if node is not a Scalar node. */ public static String asScalar(Node node) { if (node!=null && node.getNodeId()==NodeId.scalar) { return ((ScalarNode)node).getValue(); } return null; }
public static SequenceNode getValueAsSequenceNode(NodeTuple tuple, String filename) { Node valueNode = tuple.getValueNode(); requireNodeInstanceOf(SequenceNode.class, valueNode, filename, "The value should be a sequence but it is a " + valueNode.getNodeId().name()); return ((SequenceNode)valueNode); }
public static MappingNode expectMap(YamlReaderHelper config, FieldDescriptor field, Node node) { if (isEmpty(node)) { return new MappingNode(Tag.OMAP, ImmutableList.<NodeTuple>of(), false); } else if (node instanceof MappingNode) { return (MappingNode) node; } else { config.error(node, "Expected a map to merge with '%s', found '%s'.", field.getFullName(), node.getNodeId()); return new MappingNode(Tag.OMAP, ImmutableList.<NodeTuple>of(), false); } }
private Node resolveInclude(Node node) { if (node.getNodeId() == scalar && node.getTag().equals(INCLUDE_TAG)) { return includeResolver.resolve(node, resourceLoader, nodeNandler); } return node; }
public static String getValueAsString(NodeTuple tuple, String filename) { Node valueNode = tuple.getValueNode(); requireNodeInstanceOf(ScalarNode.class, valueNode, filename, "The value should be a string but it is a " + valueNode.getNodeId().name()); return ((ScalarNode)valueNode).getValue(); }
public static String getKeyAsString(NodeTuple tuple, String filename) { Node keyNode = tuple.getKeyNode(); requireNodeInstanceOf(ScalarNode.class, keyNode, filename, "The key should be a string but it is a " + keyNode.getNodeId().name()); return ((ScalarNode)keyNode).getValue(); }
private IRegion getHoverRegion(YamlFileAST ast, int offset) { if (ast != null) { Node n = ast.findNode(offset); if (n != null && n.getNodeId() == NodeId.scalar) { int start = n.getStartMark().getIndex(); int end = n.getEndMark().getIndex(); return new Region(start, end - start); } } return null; }