Search in sources :

Example 1 with NullConfigNode

use of com.google.api.codegen.configgen.nodes.NullConfigNode in project toolkit by googleapis.

the class ListTransformer method generateList.

/**
 * @param elements The data to transform into ConfigNodes
 * @param parentNode The parent of the generated list
 * @param elementTransformer Determines how to transform an individual element
 * @return The head of the list.
 */
public static <T> ConfigNode generateList(Iterable<T> elements, ConfigNode parentNode, ElementTransformer<T> elementTransformer) {
    ConfigNode elementNode = new NullConfigNode();
    ConfigNode prev = null;
    for (T elem : elements) {
        int startLine = NodeFinder.getNextLine(prev == null ? parentNode : prev);
        ConfigNode node = elementTransformer.generateElement(startLine, elem);
        if (node == null) {
            continue;
        }
        if (prev == null) {
            parentNode.setChild(node);
        } else {
            prev.insertNext(node);
        }
        if (!elementNode.isPresent()) {
            elementNode = node;
        }
        prev = node;
    }
    return elementNode;
}
Also used : NullConfigNode(com.google.api.codegen.configgen.nodes.NullConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) NullConfigNode(com.google.api.codegen.configgen.nodes.NullConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode)

Example 2 with NullConfigNode

use of com.google.api.codegen.configgen.nodes.NullConfigNode in project toolkit by googleapis.

the class ProtoPageStreamingTransformer method generateResponseValueNode.

@Override
public ConfigNode generateResponseValueNode(ConfigNode parentNode, MethodModel method, ConfigHelper helper) {
    if (!hasResponseTokenField(method)) {
        return new NullConfigNode();
    }
    String resourcesFieldName = getResourcesFieldName(method, helper);
    if (resourcesFieldName == null) {
        return new NullConfigNode();
    }
    ConfigNode tokenFieldNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(parentNode), "token_field", PAGING_PARAMETERS.getNameForNextPageToken());
    parentNode.setChild(tokenFieldNode);
    ConfigNode resourcesFieldNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(tokenFieldNode), "resources_field", resourcesFieldName);
    return tokenFieldNode.insertNext(resourcesFieldNode);
}
Also used : NullConfigNode(com.google.api.codegen.configgen.nodes.NullConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) NullConfigNode(com.google.api.codegen.configgen.nodes.NullConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode)

Example 3 with NullConfigNode

use of com.google.api.codegen.configgen.nodes.NullConfigNode in project toolkit by googleapis.

the class ConfigYamlNodeReader method readMessageNode.

private ConfigNode readMessageNode(int prevLine, MappingNode node, Descriptor messageType) {
    ConfigNode configNode = new NullConfigNode();
    ConfigNode prev = new NullConfigNode();
    for (NodeTuple entry : node.getValue()) {
        ConfigNode entryNode = readMessageNodeEntry(entry, messageType);
        ConfigNode commentNode = readCommentNode(prevLine, entry.getKeyNode(), entryNode);
        prevLine = entry.getValueNode().getEndMark().getLine() + 1;
        if (entryNode == null) {
            continue;
        }
        prev.insertNext(commentNode);
        prev = entryNode;
        if (!configNode.isPresent()) {
            configNode = commentNode;
        }
    }
    return configNode;
}
Also used : NullConfigNode(com.google.api.codegen.configgen.nodes.NullConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) NullConfigNode(com.google.api.codegen.configgen.nodes.NullConfigNode) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple)

Example 4 with NullConfigNode

use of com.google.api.codegen.configgen.nodes.NullConfigNode in project toolkit by googleapis.

the class ConfigYamlNodeReader method readMapNode.

private ConfigNode readMapNode(int prevLine, Node node, FieldDescriptor field) {
    if (isEmpty(node)) {
        return new NullConfigNode();
    }
    if (!(node instanceof MappingNode)) {
        helper.error(node, "Expected a map to merge with '%s', found '%s'.", field.getFullName(), node.getNodeId());
        return null;
    }
    Descriptor messageType = field.getMessageType();
    ConfigNode configNode = new NullConfigNode();
    ConfigNode prev = new NullConfigNode();
    for (NodeTuple entry : ((MappingNode) node).getValue()) {
        ConfigNode entryNode = readMapNodeEntry(entry, messageType);
        ConfigNode commentNode = readCommentNode(prevLine, entry.getKeyNode(), entryNode);
        prevLine = entry.getValueNode().getEndMark().getLine() + 1;
        if (entryNode == null) {
            continue;
        }
        prev.insertNext(commentNode);
        prev = entryNode;
        if (!configNode.isPresent()) {
            configNode = commentNode;
        }
    }
    return configNode;
}
Also used : MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) NullConfigNode(com.google.api.codegen.configgen.nodes.NullConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) NullConfigNode(com.google.api.codegen.configgen.nodes.NullConfigNode) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple)

Example 5 with NullConfigNode

use of com.google.api.codegen.configgen.nodes.NullConfigNode in project toolkit by googleapis.

the class ConfigYamlNodeReader method readListNode.

private ConfigNode readListNode(int prevLine, Node node, final FieldDescriptor field) {
    if (isEmpty(node)) {
        return new NullConfigNode();
    }
    if (!(node instanceof SequenceNode)) {
        return new ListItemConfigNode(helper.getStartLine(node)).setChild(readSingularField(prevLine, node, field));
    }
    ConfigNode configNode = new NullConfigNode();
    ConfigNode prev = new NullConfigNode();
    for (Node elem : ((SequenceNode) node).getValue()) {
        ConfigNode elemNode = new ListItemConfigNode(helper.getStartLine(elem)).setChild(readSingularField(prevLine, elem, field));
        ConfigNode commentNode = readCommentNode(prevLine, elem, elemNode);
        prevLine = elem.getEndMark().getLine() + 1;
        if (elemNode == null) {
            continue;
        }
        prev.insertNext(commentNode);
        prev = elemNode;
        if (!configNode.isPresent()) {
            configNode = commentNode;
        }
    }
    return configNode;
}
Also used : ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) SequenceNode(org.yaml.snakeyaml.nodes.SequenceNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) Node(org.yaml.snakeyaml.nodes.Node) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) NullConfigNode(com.google.api.codegen.configgen.nodes.NullConfigNode) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) NullConfigNode(com.google.api.codegen.configgen.nodes.NullConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) NullConfigNode(com.google.api.codegen.configgen.nodes.NullConfigNode) SequenceNode(org.yaml.snakeyaml.nodes.SequenceNode)

Aggregations

ConfigNode (com.google.api.codegen.configgen.nodes.ConfigNode)6 NullConfigNode (com.google.api.codegen.configgen.nodes.NullConfigNode)6 FieldConfigNode (com.google.api.codegen.configgen.nodes.FieldConfigNode)5 ListItemConfigNode (com.google.api.codegen.configgen.nodes.ListItemConfigNode)4 ScalarConfigNode (com.google.api.codegen.configgen.nodes.ScalarConfigNode)4 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)2 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)2 Descriptor (com.google.protobuf.Descriptors.Descriptor)1 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)1 Node (org.yaml.snakeyaml.nodes.Node)1 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)1 SequenceNode (org.yaml.snakeyaml.nodes.SequenceNode)1