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