use of com.google.api.codegen.configgen.nodes.ConfigNode 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.ConfigNode in project toolkit by googleapis.
the class ConfigGeneratorApi method generateConfig.
private Map<String, String> generateConfig(String outputPath) {
ConfigNode node = new ProtoConfigMerger().mergeConfig(model, outputPath);
ConfigGenerator configGenerator = new ConfigGenerator(0);
configGenerator.visit(node);
return ImmutableMap.of(outputPath, configGenerator.toString());
}
use of com.google.api.codegen.configgen.nodes.ConfigNode 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;
}
use of com.google.api.codegen.configgen.nodes.ConfigNode 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;
}
use of com.google.api.codegen.configgen.nodes.ConfigNode 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;
}
Aggregations