Search in sources :

Example 6 with FieldConfigNode

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;
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode)

Example 7 with FieldConfigNode

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;
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) DefaultComment(com.google.api.codegen.configgen.nodes.metadata.DefaultComment)

Example 8 with FieldConfigNode

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;
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode)

Example 9 with FieldConfigNode

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."));
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) ScalarConfigNode(com.google.api.codegen.configgen.nodes.ScalarConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) DefaultComment(com.google.api.codegen.configgen.nodes.metadata.DefaultComment)

Example 10 with FieldConfigNode

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;
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) FixmeComment(com.google.api.codegen.configgen.nodes.metadata.FixmeComment) ArrayList(java.util.ArrayList) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) FieldModel(com.google.api.codegen.config.FieldModel)

Aggregations

FieldConfigNode (com.google.api.codegen.configgen.nodes.FieldConfigNode)27 ConfigNode (com.google.api.codegen.configgen.nodes.ConfigNode)22 ListItemConfigNode (com.google.api.codegen.configgen.nodes.ListItemConfigNode)11 ScalarConfigNode (com.google.api.codegen.configgen.nodes.ScalarConfigNode)9 DefaultComment (com.google.api.codegen.configgen.nodes.metadata.DefaultComment)7 NullConfigNode (com.google.api.codegen.configgen.nodes.NullConfigNode)5 Test (org.junit.Test)5 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)3 Node (org.yaml.snakeyaml.nodes.Node)3 FixmeComment (com.google.api.codegen.configgen.nodes.metadata.FixmeComment)2 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)2 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)2 SequenceNode (org.yaml.snakeyaml.nodes.SequenceNode)2 FieldModel (com.google.api.codegen.config.FieldModel)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Yaml (org.yaml.snakeyaml.Yaml)1 ComposerException (org.yaml.snakeyaml.composer.ComposerException)1