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;
}
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();
}
}
Aggregations