Search in sources :

Example 1 with ResourceNameInitValueView

use of com.google.api.codegen.viewmodel.ResourceNameInitValueView in project toolkit by googleapis.

the class TestCaseTransformer method requireProjectIdInSmokeTest.

private boolean requireProjectIdInSmokeTest(FieldSettingView settingsView, SurfaceNamer namer) {
    InitCodeLineView line = settingsView.initCodeLine();
    if (line.lineType() == InitCodeLineType.SimpleInitLine) {
        SimpleInitCodeLineView simpleLine = (SimpleInitCodeLineView) line;
        String projectVarName = namer.localVarReference(Name.from(InitFieldConfig.PROJECT_ID_VARIABLE_NAME));
        if (simpleLine.initValue() instanceof ResourceNameInitValueView) {
            ResourceNameInitValueView initValue = (ResourceNameInitValueView) simpleLine.initValue();
            return initValue.formatArgs().contains(projectVarName);
        } else if (simpleLine.initValue() instanceof ResourceNameOneofInitValueView) {
            ResourceNameOneofInitValueView initValue = (ResourceNameOneofInitValueView) simpleLine.initValue();
            ResourceNameInitValueView subValue = initValue.specificResourceNameView();
            return subValue == null ? initValue.formatArgs().contains(projectVarName) : subValue.formatArgs().contains(projectVarName);
        } else if (simpleLine.initValue() instanceof SimpleInitValueView) {
            SimpleInitValueView initValue = (SimpleInitValueView) simpleLine.initValue();
            return initValue.initialValue().equals(projectVarName);
        } else if (simpleLine.initValue() instanceof FormattedInitValueView) {
            FormattedInitValueView initValue = (FormattedInitValueView) simpleLine.initValue();
            return initValue.formatArgs().contains(projectVarName);
        }
    }
    return false;
}
Also used : ResourceNameInitValueView(com.google.api.codegen.viewmodel.ResourceNameInitValueView) SimpleInitCodeLineView(com.google.api.codegen.viewmodel.SimpleInitCodeLineView) InitCodeLineView(com.google.api.codegen.viewmodel.InitCodeLineView) SimpleInitCodeLineView(com.google.api.codegen.viewmodel.SimpleInitCodeLineView) SimpleInitValueView(com.google.api.codegen.viewmodel.SimpleInitValueView) FormattedInitValueView(com.google.api.codegen.viewmodel.FormattedInitValueView) ResourceNameOneofInitValueView(com.google.api.codegen.viewmodel.ResourceNameOneofInitValueView)

Example 2 with ResourceNameInitValueView

use of com.google.api.codegen.viewmodel.ResourceNameInitValueView 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

ResourceNameInitValueView (com.google.api.codegen.viewmodel.ResourceNameInitValueView)2 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 FormattedInitValueView (com.google.api.codegen.viewmodel.FormattedInitValueView)1 InitCodeLineView (com.google.api.codegen.viewmodel.InitCodeLineView)1 RepeatedResourceNameInitValueView (com.google.api.codegen.viewmodel.RepeatedResourceNameInitValueView)1 ResourceNameOneofInitValueView (com.google.api.codegen.viewmodel.ResourceNameOneofInitValueView)1 SimpleInitCodeLineView (com.google.api.codegen.viewmodel.SimpleInitCodeLineView)1 SimpleInitValueView (com.google.api.codegen.viewmodel.SimpleInitValueView)1