Search in sources :

Example 1 with ScalarConfigNode

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

the class ConfigMerger method mergeVersion.

private ConfigNode mergeVersion(ConfigNode configNode, ConfigNode prevNode) {
    FieldConfigNode versionNode = MissingFieldTransformer.insert("config_schema_version", configNode, prevNode).generate();
    if (!NodeFinder.hasContent(versionNode.getChild())) {
        return versionNode.setChild(new ScalarConfigNode(versionNode.getStartLine(), CONFIG_SCHEMA_VERSION));
    }
    String version = versionNode.getChild().getText();
    if (CONFIG_SCHEMA_VERSION.equals(version)) {
        return versionNode;
    }
    helper.error(versionNode.getStartLine(), "The specified configuration schema version '%s' is unsupported.", version);
    return null;
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode)

Example 2 with ScalarConfigNode

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

the class ConfigMerger method mergeType.

private ConfigNode mergeType(ConfigNode configNode) {
    FieldConfigNode typeNode = MissingFieldTransformer.prepend("type", configNode).generate();
    if (!NodeFinder.hasContent(typeNode.getChild())) {
        return typeNode.setChild(new ScalarConfigNode(typeNode.getStartLine(), CONFIG_PROTO_TYPE));
    }
    String type = typeNode.getChild().getText();
    if (CONFIG_PROTO_TYPE.equals(type)) {
        return typeNode;
    }
    helper.error(typeNode.getStartLine(), "The specified configuration type '%s' is unknown.", type);
    return null;
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode)

Example 3 with ScalarConfigNode

use of com.google.api.codegen.configgen.nodes.ScalarConfigNode 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 4 with ScalarConfigNode

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

the class ConfigYamlNodeReader method readCommentNode.

private ConfigNode readCommentNode(int prevLine, Node node, ConfigNode configNode) {
    int startLine = node.getStartMark().getLine();
    int endLine = node.getEndMark().getLine();
    List<String> commentLines = startLine <= prevLine ? new ArrayList<>() : new ArrayList<>(lines.subList(prevLine, startLine));
    for (String line : lines.subList(startLine, endLine + 1)) {
        int commentIndex = line.indexOf("#");
        if (commentIndex >= 0) {
            commentLines.add(line.substring(commentIndex));
        }
    }
    if (commentLines.isEmpty()) {
        return configNode;
    }
    String comment = Joiner.on(System.lineSeparator()).join(commentLines);
    return new ScalarConfigNode(startLine + 1, comment).insertNext(configNode);
}
Also used : ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode)

Example 5 with ScalarConfigNode

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

the class LanguageSettingsMerger method mergePackageNameValue.

private ConfigNode mergePackageNameValue(ConfigNode packageNameNode, LanguageFormatter languageFormatter, String packageName) {
    ConfigNode packageNameValueNode = new ScalarConfigNode(packageNameNode.getStartLine(), languageFormatter.getFormattedPackageName(packageName));
    packageNameNode.setChild(packageNameValueNode);
    return packageNameValueNode;
}
Also used : ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode)

Aggregations

ScalarConfigNode (com.google.api.codegen.configgen.nodes.ScalarConfigNode)5 FieldConfigNode (com.google.api.codegen.configgen.nodes.FieldConfigNode)4 ConfigNode (com.google.api.codegen.configgen.nodes.ConfigNode)2 ListItemConfigNode (com.google.api.codegen.configgen.nodes.ListItemConfigNode)1 Test (org.junit.Test)1