public List<ApiCallSettingsView> generateApiCallableSettings(MethodContext context) { List<ApiCallSettingsView> settings = new ArrayList<>(); MethodConfig methodConfig = context.getMethodConfig(); if (methodConfig.isGrpcStreaming()) { settings.add( generateApiCallableSettings( context, ApiCallableImplType.of(methodConfig.getGrpcStreamingType()))); } else if (methodConfig.isPageStreaming()) { settings.add(generateApiCallableSettings(context, ApiCallableImplType.PagedApiCallable)); } else if (methodConfig.isBatching()) { settings.add(generateApiCallableSettings(context, ApiCallableImplType.BatchingApiCallable)); } else if (methodConfig.isLongRunningOperation()) { if (context.getFeatureConfig().enableRawOperationCallSettings()) { settings.add(generateApiCallableSettings(context, ApiCallableImplType.SimpleApiCallable)); } settings.add(generateApiCallableSettings(context, ApiCallableImplType.OperationApiCallable)); } else { settings.add(generateApiCallableSettings(context, ApiCallableImplType.SimpleApiCallable)); } return settings; }
@Before public void setUp() { valueSet = SampleValueSet.newBuilder().setId("test-sample-value-set-id").build(); parent = new OutputTransformer.ScopeTable(); child = new OutputTransformer.ScopeTable(parent); MockitoAnnotations.initMocks(this); when(context.getFeatureConfig()).thenReturn(featureConfig); when(context.getMethodConfig()).thenReturn(config); when(context.getMethodModel()).thenReturn(model); when(context.getNamer()).thenReturn(namer); when(context.getTypeTable()).thenReturn(typeTable); when(model.getSimpleName()).thenReturn("methodSimpleName"); when(namer.getSampleResponseVarName(context)).thenReturn("sampleResponseVarName"); }
private List<PagedResponseIterateMethodView> getIterateMethods(MethodContext context) { SurfaceNamer namer = context.getNamer(); List<PagedResponseIterateMethodView> iterateMethods = new ArrayList<>(); FieldConfig resourceFieldConfig = context.getMethodConfig().getPageStreaming().getResourcesFieldConfig(); if (context.getFeatureConfig().useResourceNameFormatOption(resourceFieldConfig)) { String resourceTypeName = namer.getAndSaveElementResourceTypeName(context.getTypeTable(), resourceFieldConfig); String resourceTypeIterateMethodName = namer.getPagedResponseIterateMethod(context.getFeatureConfig(), resourceFieldConfig); String resourceTypeGetValuesMethodName = namer.getPageGetValuesMethod(context.getFeatureConfig(), resourceFieldConfig); String parseMethodName = namer.getResourceTypeParseMethodName(context.getTypeTable(), resourceFieldConfig); PagedResponseIterateMethodView.Builder iterateMethod = PagedResponseIterateMethodView.newBuilder() .overloadResourceTypeName(resourceTypeName) .overloadResourceTypeParseFunctionName(parseMethodName) .overloadResourceTypeIterateMethodName(resourceTypeIterateMethodName) .overloadResourceTypeGetValuesMethodName(resourceTypeGetValuesMethodName) .iterateMethodName(namer.getPagedResponseIterateMethod()) .getValuesMethodName(namer.getPageGetValuesMethod()); iterateMethods.add(iterateMethod.build()); } return iterateMethods; }
private InitCodeLineView generateListInitCodeLine(MethodContext context, InitCodeNode item) { ListInitCodeLineView.Builder surfaceLine = ListInitCodeLineView.newBuilder(); FieldConfig fieldConfig = item.getFieldConfig(); SurfaceNamer namer = context.getNamer(); ImportTypeTable typeTable = context.getTypeTable(); surfaceLine.lineType(InitCodeLineType.ListInitLine); surfaceLine.identifier(namer.localVarName(item.getIdentifier())); if (context.getFeatureConfig().useResourceNameFormatOptionInSample(context, fieldConfig)) { surfaceLine.elementTypeName(namer.getAndSaveElementResourceTypeName(typeTable, fieldConfig)); } else { surfaceLine.elementTypeName( typeTable.getAndSaveNicknameForElementType(item.getType().makeOptional())); } List<String> entries = new ArrayList<>(); List<InitCodeLineView> elements = new ArrayList<>(); for (InitCodeNode child : item.getChildren().values()) { entries.add(namer.localVarName(child.getIdentifier())); elements.add(generateSurfaceInitCodeLine(context, child, elements.isEmpty(), false)); } surfaceLine.elementIdentifiers(entries); surfaceLine.elements(elements); return surfaceLine.build(); }
private static String getVariableName(MethodContext context, InitCodeNode item) { if (!context .getFeatureConfig() .useResourceNameFormatOptionInSample(context, item.getFieldConfig()) && item.getInitValueConfig().hasFormattingConfig()) { return context.getNamer().getFormattedVariableName(item.getIdentifier()); } return context.getNamer().localVarName(item.getIdentifier()); } }
.build()); if (methodContext.getFeatureConfig().useResourceNameFormatOption(resourcesFieldConfig)) { resourceTypeName = methodContext namer.getFieldGetFunctionName(methodContext.getFeatureConfig(), resourcesFieldConfig); if (methodContext.getFeatureConfig().useResourceNameConverters(resourcesFieldConfig)) { expectedTransformFunction = namer.getResourceTypeParseMethodName( .resourcesIterateMethod( namer.getPagedResponseIterateMethod( methodContext.getFeatureConfig(), resourcesFieldConfig)) .expectedValueTransformFunction(expectedTransformFunction) .resourcesVarName(namer.localVarName(Name.from("resource_names")))
private List<PathTemplateCheckView> generatePathTemplateChecks( MethodContext context, Iterable<FieldConfig> fieldConfigs) { List<PathTemplateCheckView> pathTemplateChecks = new ArrayList<>(); if (!context.getFeatureConfig().enableStringFormatFunctions()) { return pathTemplateChecks;
namer.getFieldGetFunctionName(methodContext.getFeatureConfig(), fieldConfig); if (methodContext.getFeatureConfig().useResourceNameFormatOption(fieldConfig)) { if (fieldConfig.requiresParamTransformationFromAny()) { expectedTransformFunction = namer.getToStringMethod(); actualTransformFunction = namer.getToStringMethod(); } else if (fieldConfig.requiresParamTransformation()) { if (methodContext.getFeatureConfig().useResourceNameConverters(fieldConfig)) { expectedTransformFunction = namer.getToStringMethod(); } else { namer.getResourceOneofCreateMethod(methodContext.getTypeTable(), fieldConfig); } else if (methodContext.getFeatureConfig().useResourceNameConverters(fieldConfig)) { if (fieldConfig.getField().isRepeated()) { actualTransformFunction =
if (context.getFeatureConfig().useResourceNameFormatOption(resourceFieldConfig)) { resourceTypeName = namer.getAndSaveElementResourceTypeName(typeTable, resourceFieldConfig); } else { namer.getPagedResponseIterateMethod(context.getFeatureConfig(), resourceFieldConfig); namer.getFieldGetFunctionName(context.getFeatureConfig(), resourceFieldConfig);
context.getFeatureConfig(), context.getMethodConfig().getPageStreaming().getResourcesFieldConfig()); PageStreamingConfig pageStreaming = context.getMethodConfig().getPageStreaming(); FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig(); if (context.getFeatureConfig().useResourceNameConverters(resourceFieldConfig)) { resourceListParseFunction = namer.getResourceTypeParseListMethodName(context.getTypeTable(), resourceFieldConfig);
public RequestObjectParamView generateRequestObjectParam( MethodContext context, FieldConfig fieldConfig) { SurfaceNamer namer = context.getNamer(); FeatureConfig featureConfig = context.getFeatureConfig(); ImportTypeTable typeTable = context.getTypeTable(); FieldModel field = fieldConfig.getField(); "StaticLangApiMethodTransformer.generateRequestObjectParam - elementTypeName"); if (context.getFeatureConfig().useResourceNameFormatOption(fieldConfig)) { if (namer.shouldImportRequestObjectParamType(field)) { typeName = namer.getAndSaveResourceTypeName(typeTable, fieldConfig); String transformParamFunctionName = null; String formatMethodName = null; if (context.getFeatureConfig().useResourceNameFormatOption(fieldConfig)) { if (fieldConfig.requiresParamTransformation() && !fieldConfig.requiresParamTransformationFromAny() transformParamFunctionName = namer.getResourceOneofCreateMethod(typeTable, fieldConfig); if (context.getFeatureConfig().useResourceNameConverters(fieldConfig)) { if (field.isRepeated()) {
pageStreaming && context .getFeatureConfig() .useResourceNameFormatOption( context.getMethodConfig().getPageStreaming().getResourcesFieldConfig());
@Override public String getOptionalFieldDefaultValue(FieldConfig fieldConfig, MethodContext context) { // Need to provide defaults for primitives, enums, strings, and repeated (including maps) FieldModel type = fieldConfig.getField(); if (context.getFeatureConfig().useResourceNameFormatOption(fieldConfig)) { if (type.isRepeated()) { TypeNameConverter typeNameConverter = getTypeNameConverter(); TypeName elementTypeName = typeNameConverter.getTypeName(getResourceTypeName(fieldConfig.getResourceNameConfig())); TypeName enumerableTypeName = typeNameConverter.getTypeName("System.Linq.Enumerable"); TypeName emptyTypeName = new TypeName( enumerableTypeName.getFullName(), enumerableTypeName.getNickname(), "%s.Empty<%i>", elementTypeName); return TypedValue.create(emptyTypeName, "%s()") .getValueAndSaveTypeNicknameIn((CSharpTypeTable) typeNameConverter); } else { return null; } } else { if (type.isPrimitive() || type.isEnum() || type.isRepeated()) { return context.getTypeTable().getImplZeroValueAndSaveNicknameFor(type); } else { return null; } } }
FieldConfig fieldConfig = item.getFieldConfig(); if (context.getFeatureConfig().useResourceNameProtoAccessor(fieldConfig)) { fieldSetting.fieldSetFunction( namer.getResourceNameFieldSetFunctionName(fieldConfig.getMessageFieldConfig())); context.getFeatureConfig().useResourceNameConvertersInSampleOnly(context, fieldConfig); if (context.getFeatureConfig().useResourceNameConverters(fieldConfig) && !context.isFlattenedMethodContext()) { needsConversion = true;
private InitCodeLineView generateSimpleInitCodeLine( MethodContext context, InitCodeNode item, boolean isFirstItem) { SimpleInitCodeLineView.Builder surfaceLine = SimpleInitCodeLineView.newBuilder(); FieldConfig fieldConfig = item.getFieldConfig(); SurfaceNamer namer = context.getNamer(); ImportTypeTable typeTable = context.getTypeTable(); surfaceLine.lineType(InitCodeLineType.SimpleInitLine); if (context.getFeatureConfig().useResourceNameFormatOptionInSample(context, fieldConfig)) { if (!context.isFlattenedMethodContext()) { // In a non-flattened context, we always use the resource name type set on the message // instead of set on the flattened method fieldConfig = fieldConfig.getMessageFieldConfig(); } if (item.getType().isRepeated()) { surfaceLine.typeName(namer.getAndSaveResourceTypeName(typeTable, fieldConfig)); } else { surfaceLine.typeName(namer.getAndSaveElementResourceTypeName(typeTable, fieldConfig)); } } else { surfaceLine.typeName(typeTable.getAndSaveNicknameFor(item.getType())); } surfaceLine.identifier(getVariableName(context, item)); setInitValueAndComments(surfaceLine, context, item, isFirstItem); return surfaceLine.build(); }
String comment = ""; if (context.getFeatureConfig().useResourceNameFormatOptionInSample(context, fieldConfig)) { if (!context.isFlattenedMethodContext()) { ResourceNameConfig messageResNameConfig = fieldConfig.getMessageResourceNameConfig(); if (context.getFeatureConfig().enableStringFormatFunctions() || fieldConfig.getResourceNameConfig() == null) { FormattedInitValueView.Builder formattedInitValue = FormattedInitValueView.newBuilder();