Search in sources :

Example 1 with ListItemConfigNode

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

the class InterfaceMerger method generateInterfaceNode.

private ListItemConfigNode generateInterfaceNode(int startLine, InterfaceModel apiInterface) {
    Map<String, String> collectionNameMap = interfaceTransformer.getResourceToEntityNameMap(apiInterface);
    ListItemConfigNode interfaceNode = new ListItemConfigNode(startLine);
    FieldConfigNode nameNode = FieldConfigNode.createStringPair(startLine, "name", apiInterface.getFullName()).setComment(new DefaultComment("The fully qualified name of the API interface."));
    interfaceNode.setChild(nameNode);
    ConfigNode collectionsNode = collectionMerger.generateCollectionsNode(nameNode, collectionNameMap);
    ConfigNode retryParamsDefNode = retryMerger.generateRetryDefinitionsNode(collectionsNode);
    methodMerger.generateMethodsNode(interfaceNode, apiInterface, collectionNameMap);
    return interfaceNode;
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) DefaultComment(com.google.api.codegen.configgen.nodes.metadata.DefaultComment)

Example 2 with ListItemConfigNode

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

the class RetryMerger method generateRetryCodeDefNode.

private ConfigNode generateRetryCodeDefNode(int startLine, String name, List<String> codes) {
    ConfigNode retryCodeDefNode = new ListItemConfigNode(startLine);
    ConfigNode nameNode = FieldConfigNode.createStringPair(startLine, "name", name);
    retryCodeDefNode.setChild(nameNode);
    ConfigNode retryCodesNode = new FieldConfigNode(NodeFinder.getNextLine(nameNode), "retry_codes");
    nameNode.insertNext(retryCodesNode);
    ListTransformer.generateStringList(codes, retryCodesNode);
    return retryCodeDefNode;
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode)

Example 3 with ListItemConfigNode

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

the class RetryMerger method generateRetryParamDefNode.

private ConfigNode generateRetryParamDefNode(int startLine, String name) {
    ConfigNode retryParamDefNode = new ListItemConfigNode(startLine);
    ConfigNode nameNode = FieldConfigNode.createStringPair(startLine, "name", name);
    retryParamDefNode.setChild(nameNode);
    ConfigNode initialRetryDelayMillisNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(nameNode), "initial_retry_delay_millis", "100");
    nameNode.insertNext(initialRetryDelayMillisNode);
    ConfigNode retryDelayMultiplierNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(initialRetryDelayMillisNode), "retry_delay_multiplier", "1.3");
    initialRetryDelayMillisNode.insertNext(retryDelayMultiplierNode);
    ConfigNode maxRetryDelayMillisNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(retryDelayMultiplierNode), "max_retry_delay_millis", "60000");
    retryDelayMultiplierNode.insertNext(maxRetryDelayMillisNode);
    ConfigNode initialRpcTimeoutMillisNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(maxRetryDelayMillisNode), "initial_rpc_timeout_millis", "20000");
    maxRetryDelayMillisNode.insertNext(initialRpcTimeoutMillisNode);
    ConfigNode rpcTimeoutMultiplierNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(initialRpcTimeoutMillisNode), "rpc_timeout_multiplier", "1");
    initialRpcTimeoutMillisNode.insertNext(rpcTimeoutMultiplierNode);
    ConfigNode maxRpcTimeoutMillisNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(rpcTimeoutMultiplierNode), "max_rpc_timeout_millis", "20000");
    rpcTimeoutMultiplierNode.insertNext(maxRpcTimeoutMillisNode);
    ConfigNode totalTimeoutMillisNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(maxRpcTimeoutMillisNode), "total_timeout_millis", "600000");
    maxRpcTimeoutMillisNode.insertNext(totalTimeoutMillisNode);
    return retryParamDefNode;
}
Also used : ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode)

Example 4 with ListItemConfigNode

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

the class ListTransformerTest method testGenerateList.

@Test
public void testGenerateList() throws Exception {
    List<Integer> elements = Arrays.asList(1, 2);
    ConfigNode parent = new FieldConfigNode(0, "parent");
    ConfigNode listNode = ListTransformer.generateList(elements, parent, (startLine, element) -> new ListItemConfigNode(startLine).setChild(new ScalarConfigNode(startLine, String.valueOf(element))));
    int index = 0;
    for (ConfigNode node : NodeFinder.getChildren(parent)) {
        Truth.assertThat(node.getChild().getText()).isEqualTo(String.valueOf(elements.get(index++)));
    }
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) Test(org.junit.Test)

Example 5 with ListItemConfigNode

use of com.google.api.codegen.configgen.nodes.ListItemConfigNode 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)8 FieldConfigNode (com.google.api.codegen.configgen.nodes.FieldConfigNode)8 ListItemConfigNode (com.google.api.codegen.configgen.nodes.ListItemConfigNode)8 ScalarConfigNode (com.google.api.codegen.configgen.nodes.ScalarConfigNode)2 NullConfigNode (com.google.api.codegen.configgen.nodes.NullConfigNode)1 DefaultComment (com.google.api.codegen.configgen.nodes.metadata.DefaultComment)1 FixmeComment (com.google.api.codegen.configgen.nodes.metadata.FixmeComment)1 Test (org.junit.Test)1 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)1 Node (org.yaml.snakeyaml.nodes.Node)1 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)1 SequenceNode (org.yaml.snakeyaml.nodes.SequenceNode)1