Search in sources :

Example 1 with ResourceNamePatternConfig

use of com.google.api.codegen.config.ResourceNamePatternConfig in project toolkit by googleapis.

the class InitCodeTransformer method createResourceNameOneofInitValueView.

private ResourceNameOneofInitValueView createResourceNameOneofInitValueView(MethodContext context, FieldConfig fieldConfig, InitCodeNode item, boolean convertToString) {
    ResourceNameOneofConfig oneofConfig = (ResourceNameOneofConfig) fieldConfig.getResourceNameConfig();
    SurfaceNamer namer = context.getNamer();
    ImportTypeTable typeTable = context.getTypeTable();
    if (context.getFeatureConfig().useStaticCreateMethodForOneofs()) {
        ResourceNamePatternConfig pattern = getMatchingResourceNamePattern(item, oneofConfig);
        String createMethod = convertToString ? pattern.getFormatMethodName() : pattern.getCreateMethodName();
        ImmutableList<String> formatArgs = getFormatFunctionArgs(context, ImmutableList.copyOf(pattern.getBindingVariables()), item.getInitValueConfig());
        return ResourceNameOneofInitValueView.newBuilder().resourceOneofTypeName(namer.getAndSaveElementResourceTypeName(typeTable, fieldConfig)).createMethodName(createMethod).formatArgs(formatArgs).build();
    } else {
        SingleResourceNameConfig singleResourceNameConfig = getMatchingSingleResourceNameConfig(context, item, oneofConfig);
        FieldConfig singleResourceNameFieldConfig = fieldConfig.withResourceNameConfig(singleResourceNameConfig);
        ResourceNameInitValueView initView = createResourceNameInitValueView(context, singleResourceNameFieldConfig, item).convertToString(convertToString).build();
        return ResourceNameOneofInitValueView.newBuilder().resourceOneofTypeName(namer.getAndSaveElementResourceTypeName(typeTable, fieldConfig)).specificResourceNameView(initView).build();
    }
}
Also used : ResourceNamePatternConfig(com.google.api.codegen.config.ResourceNamePatternConfig) RepeatedResourceNameInitValueView(com.google.api.codegen.viewmodel.RepeatedResourceNameInitValueView) ResourceNameInitValueView(com.google.api.codegen.viewmodel.ResourceNameInitValueView) ResourceNameOneofConfig(com.google.api.codegen.config.ResourceNameOneofConfig) FieldConfig(com.google.api.codegen.config.FieldConfig) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig)

Aggregations

FieldConfig (com.google.api.codegen.config.FieldConfig)1 ResourceNameOneofConfig (com.google.api.codegen.config.ResourceNameOneofConfig)1 ResourceNamePatternConfig (com.google.api.codegen.config.ResourceNamePatternConfig)1 SingleResourceNameConfig (com.google.api.codegen.config.SingleResourceNameConfig)1 RepeatedResourceNameInitValueView (com.google.api.codegen.viewmodel.RepeatedResourceNameInitValueView)1 ResourceNameInitValueView (com.google.api.codegen.viewmodel.ResourceNameInitValueView)1