use of com.google.api.codegen.configgen.nodes.FieldConfigNode 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.FieldConfigNode in project toolkit by googleapis.
the class InterfaceMerger method generateInterfaceNode.
private ListItemConfigNode generateInterfaceNode(int startLine, InterfaceModel apiInterface) {
Map<String, String> collectionNameMap = interfaceTransformer.getResourceToEntityNameMap(apiInterface);
ListItemConfigNode interfaceNode = new ListItemConfigNode(startLine);
FieldConfigNode nameNode = FieldConfigNode.createStringPair(startLine, "name", apiInterface.getFullName()).setComment(new DefaultComment("The fully qualified name of the API interface."));
interfaceNode.setChild(nameNode);
ConfigNode collectionsNode = collectionMerger.generateCollectionsNode(nameNode, collectionNameMap);
ConfigNode retryParamsDefNode = retryMerger.generateRetryDefinitionsNode(collectionsNode);
methodMerger.generateMethodsNode(interfaceNode, apiInterface, collectionNameMap);
return interfaceNode;
}
use of com.google.api.codegen.configgen.nodes.FieldConfigNode in project toolkit by googleapis.
the class LanguageSettingsMerger method mergeLanguageSetting.
private ConfigNode mergeLanguageSetting(ConfigNode languageNode, LanguageFormatter languageFormatter, String packageName) {
ConfigNode packageNameNode = new FieldConfigNode(NodeFinder.getNextLine(languageNode), "package_name");
languageNode.setChild(packageNameNode);
mergePackageNameValue(packageNameNode, languageFormatter, packageName);
return packageNameNode;
}
use of com.google.api.codegen.configgen.nodes.FieldConfigNode in project toolkit by googleapis.
the class LanguageSettingsMerger method mergeLanguageSettings.
public ConfigNode mergeLanguageSettings(final String packageName, ConfigNode configNode, ConfigNode prevNode) {
FieldConfigNode languageSettingsNode = MissingFieldTransformer.insert("language_settings", configNode, prevNode).generate();
if (NodeFinder.hasContent(languageSettingsNode.getChild())) {
return languageSettingsNode;
}
ConfigNode languageSettingsValueNode = ListTransformer.generateList(LANGUAGE_FORMATTERS.entrySet(), languageSettingsNode, (startLine, entry) -> {
ConfigNode languageNode = new FieldConfigNode(startLine, entry.getKey());
mergeLanguageSetting(languageNode, entry.getValue(), packageName);
return languageNode;
});
return languageSettingsNode.setChild(languageSettingsValueNode).setComment(new DefaultComment("The settings of generated code in a specific language."));
}
use of com.google.api.codegen.configgen.nodes.FieldConfigNode in project toolkit by googleapis.
the class MethodMerger method generateField.
private ConfigNode generateField(ConfigNode prevNode, MethodModel method) {
List<String> parameterList = new ArrayList<>();
for (FieldModel field : method.getInputFields()) {
String fieldName = field.getSimpleName();
if (field.getOneof() == null && !methodTransformer.isIgnoredParameter(fieldName)) {
parameterList.add(fieldName);
}
}
if (parameterList.size() > 0 && parameterList.size() <= FLATTENING_THRESHOLD) {
prevNode = generateFlatteningNode(prevNode, parameterList);
}
FieldConfigNode requiredFieldsNode = new FieldConfigNode(NodeFinder.getNextLine(prevNode), "required_fields");
requiredFieldsNode.setComment(new FixmeComment("Configure which fields are required."));
ConfigNode requiredFieldsValueNode = ListTransformer.generateStringList(parameterList, requiredFieldsNode);
if (requiredFieldsValueNode.isPresent()) {
prevNode.insertNext(requiredFieldsNode);
prevNode = requiredFieldsNode;
}
// use all fields for the following check; if there are ignored fields for flattening
// purposes, the caller still needs a way to set them (by using the request object method).
int fieldCount = Iterables.size(method.getInputFields());
boolean requestObjectMethod = (fieldCount > REQUEST_OBJECT_METHOD_THRESHOLD || fieldCount != parameterList.size()) && !method.getRequestStreaming();
ConfigNode requestObjectMethodNode = FieldConfigNode.createStringPair(NodeFinder.getNextLine(prevNode), "request_object_method", String.valueOf(requestObjectMethod));
prevNode.insertNext(requestObjectMethodNode);
return requestObjectMethodNode;
}
Aggregations