Search in sources :

Example 6 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode 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 7 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode 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 8 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode 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 9 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode 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)

Example 10 with ConfigNode

use of com.google.api.codegen.configgen.nodes.ConfigNode in project toolkit by googleapis.

the class MethodMerger method generateMethodsNode.

public void generateMethodsNode(ConfigNode parentNode, InterfaceModel apiInterface, Map<String, String> collectionNameMap) {
    ConfigNode prevNode = NodeFinder.getLastChild(parentNode);
    FieldConfigNode methodsNode = new FieldConfigNode(NodeFinder.getNextLine(prevNode), "methods").setComment(new DefaultComment(METHODS_COMMENT));
    prevNode.insertNext(methodsNode);
    generateMethodsValueNode(methodsNode, apiInterface, collectionNameMap);
}
Also used : FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) ConfigNode(com.google.api.codegen.configgen.nodes.ConfigNode) ListItemConfigNode(com.google.api.codegen.configgen.nodes.ListItemConfigNode) FieldConfigNode(com.google.api.codegen.configgen.nodes.FieldConfigNode) DefaultComment(com.google.api.codegen.configgen.nodes.metadata.DefaultComment)

Aggregations

ConfigNode (com.google.api.codegen.configgen.nodes.ConfigNode)39 FieldConfigNode (com.google.api.codegen.configgen.nodes.FieldConfigNode)35 ListItemConfigNode (com.google.api.codegen.configgen.nodes.ListItemConfigNode)22 ScalarConfigNode (com.google.api.codegen.configgen.nodes.ScalarConfigNode)12 NullConfigNode (com.google.api.codegen.configgen.nodes.NullConfigNode)11 Test (org.junit.Test)5 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)5 DefaultComment (com.google.api.codegen.configgen.nodes.metadata.DefaultComment)4 FixmeComment (com.google.api.codegen.configgen.nodes.metadata.FixmeComment)4 Node (org.yaml.snakeyaml.nodes.Node)4 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)3 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)3 SequenceNode (org.yaml.snakeyaml.nodes.SequenceNode)3 ConfigHelper (com.google.api.codegen.configgen.ConfigHelper)2 ConfigYamlReader (com.google.api.codegen.configgen.ConfigYamlReader)2 MessageGenerator (com.google.api.codegen.configgen.MessageGenerator)2 File (java.io.File)2 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)2 FieldModel (com.google.api.codegen.config.FieldModel)1 ProtoConfigMerger (com.google.api.codegen.configgen.mergers.ProtoConfigMerger)1