Search in sources :

Example 16 with FieldConfigNode

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

the class MissingFieldTransformerTest method testPrepend.

@Test
public void testPrepend() throws Exception {
    ConfigNode parent = new FieldConfigNode(0, "parent");
    Map<String, String> fields = ImmutableMap.of("B", "2", "C", "3");
    ListTransformer.generateList(fields.entrySet(), parent, (startLine, entry) -> FieldConfigNode.createStringPair(startLine, entry.getKey(), entry.getValue()));
    MissingFieldTransformer.prepend("A", parent).generate();
    List<String> fieldNames = Arrays.asList("A", "B", "C");
    int index = 0;
    for (ConfigNode node : NodeFinder.getChildren(parent)) {
        Truth.assertThat(node.getText()).isEqualTo(fieldNames.get(index++));
    }
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) Test(org.junit.Test)

Example 17 with FieldConfigNode

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

the class MissingFieldTransformerTest method testAppend.

@Test
public void testAppend() throws Exception {
    ConfigNode parent = new FieldConfigNode(0, "parent");
    Map<String, String> fields = ImmutableMap.of("A", "1", "B", "2");
    ListTransformer.generateList(fields.entrySet(), parent, (startLine, entry) -> FieldConfigNode.createStringPair(startLine, entry.getKey(), entry.getValue()));
    MissingFieldTransformer.append("C", parent).generate();
    List<String> fieldNames = Arrays.asList("A", "B", "C");
    int index = 0;
    for (ConfigNode node : NodeFinder.getChildren(parent)) {
        Truth.assertThat(node.getText()).isEqualTo(fieldNames.get(index++));
    }
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) Test(org.junit.Test)

Example 18 with FieldConfigNode

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

the class MissingFieldTransformerTest method testInsert.

@Test
public void testInsert() throws Exception {
    ConfigNode parent = new FieldConfigNode(0, "parent");
    Map<String, String> fields = ImmutableMap.of("A", "1", "C", "3");
    ConfigNode fieldA = ListTransformer.generateList(fields.entrySet(), parent, (startLine, entry) -> FieldConfigNode.createStringPair(startLine, entry.getKey(), entry.getValue()));
    MissingFieldTransformer.insert("B", parent, fieldA).generate();
    List<String> fieldNames = Arrays.asList("A", "B", "C");
    int index = 0;
    for (ConfigNode node : NodeFinder.getChildren(parent)) {
        Truth.assertThat(node.getText()).isEqualTo(fieldNames.get(index++));
    }
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) Test(org.junit.Test)

Example 19 with FieldConfigNode

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

the class MissingFieldTransformer method generate.

public FieldConfigNode generate() {
    ConfigNode node = NodeFinder.findByValue(parent, name);
    if (node instanceof FieldConfigNode) {
        return (FieldConfigNode) node;
    }
    if (prev == null) {
        ConfigNode next = parent.getChild();
        int startLine = next.isPresent() ? next.getStartLine() : parent.getStartLine() + 1;
        node = new FieldConfigNode(startLine, name);
        parent.setChild(node.insertNext(next));
    } else {
        ConfigNode next = node.getNext();
        node = new FieldConfigNode(NodeFinder.getNextLine(prev), name);
        prev.insertNext(node.insertNext(next));
    }
    return ((FieldConfigNode) node);
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode)

Example 20 with FieldConfigNode

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

the class CollectionMerger method generateCollectionsNode.

public ConfigNode generateCollectionsNode(ConfigNode prevNode, Map<String, String> nameMap) {
    FieldConfigNode collectionsNode = new FieldConfigNode(NodeFinder.getNextLine(prevNode), "collections").setComment(new DefaultComment(COLLECTIONS_COMMENT));
    prevNode.insertNext(collectionsNode);
    ListTransformer.generateList(nameMap.entrySet(), collectionsNode, (startLine, entry) -> generateCollectionNode(startLine, entry.getKey(), entry.getValue()));
    return collectionsNode;
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) DefaultComment(com.google.api.codegen.configgen.nodes.metadata.DefaultComment)

Aggregations

FieldConfigNode (com.google.api.codegen.configgen.nodes.FieldConfigNode)27 ConfigNode (com.google.api.codegen.configgen.nodes.ConfigNode)22 ListItemConfigNode (com.google.api.codegen.configgen.nodes.ListItemConfigNode)11 ScalarConfigNode (com.google.api.codegen.configgen.nodes.ScalarConfigNode)9 DefaultComment (com.google.api.codegen.configgen.nodes.metadata.DefaultComment)7 NullConfigNode (com.google.api.codegen.configgen.nodes.NullConfigNode)5 Test (org.junit.Test)5 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)3 Node (org.yaml.snakeyaml.nodes.Node)3 FixmeComment (com.google.api.codegen.configgen.nodes.metadata.FixmeComment)2 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)2 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)2 SequenceNode (org.yaml.snakeyaml.nodes.SequenceNode)2 FieldModel (com.google.api.codegen.config.FieldModel)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Yaml (org.yaml.snakeyaml.Yaml)1 ComposerException (org.yaml.snakeyaml.composer.ComposerException)1