use of com.google.api.codegen.configgen.nodes.NullConfigNode in project toolkit by googleapis.
the class ListTransformer method generateList.
/**
* @param elements The data to transform into ConfigNodes
* @param parentNode The parent of the generated list
* @param elementTransformer Determines how to transform an individual element
* @return The head of the list.
*/
public static <T> ConfigNode generateList(Iterable<T> elements, ConfigNode parentNode, ElementTransformer<T> elementTransformer) {
ConfigNode elementNode = new NullConfigNode();
ConfigNode prev = null;
for (T elem : elements) {
int startLine = NodeFinder.getNextLine(prev == null ? parentNode : prev);
ConfigNode node = elementTransformer.generateElement(startLine, elem);
if (node == null) {
continue;
}
if (prev == null) {
parentNode.setChild(node);
} else {
prev.insertNext(node);
}
if (!elementNode.isPresent()) {
elementNode = node;
}
prev = node;
}
return elementNode;
}
use of com.google.api.codegen.configgen.nodes.NullConfigNode in project toolkit by googleapis.
the class ProtoPageStreamingTransformer method generateResponseValueNode.
@Override
public ConfigNode generateResponseValueNode(ConfigNode parentNode, MethodModel method, ConfigHelper helper) {
if (!hasResponseTokenField(method)) {
return new NullConfigNode();
}
String resourcesFieldName = getResourcesFieldName(method, helper);
if (resourcesFieldName == null) {
return new NullConfigNode();
}
ConfigNode tokenFieldNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(parentNode), "token_field", PAGING_PARAMETERS.getNameForNextPageToken());
parentNode.setChild(tokenFieldNode);
ConfigNode resourcesFieldNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(tokenFieldNode), "resources_field", resourcesFieldName);
return tokenFieldNode.insertNext(resourcesFieldNode);
}
use of com.google.api.codegen.configgen.nodes.NullConfigNode 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.NullConfigNode 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.NullConfigNode 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