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++));
}
}
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++));
}
}
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++));
}
}
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);
}
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;
}
Aggregations