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()); } }
protected void setServiceResponseTypeName( MethodContext context, StaticLangApiMethodView.Builder methodViewBuilder) { SurfaceNamer namer = context.getNamer(); if (context.getMethodConfig().isGrpcStreaming()) { // Only applicable for protobuf APIs. String returnTypeFullName = namer.getGrpcStreamingApiReturnTypeName(context, context.getTypeTable()); String returnTypeNickname = context.getTypeTable().getAndSaveNicknameFor(returnTypeFullName); methodViewBuilder.serviceResponseTypeName(returnTypeNickname); } else { String responseTypeName = context .getMethodModel() .getAndSaveResponseTypeName(context.getTypeTable(), context.getNamer()); methodViewBuilder.serviceResponseTypeName(responseTypeName); } }
private String getMethodDescriptorName(MethodContext context) { if (context.getProductConfig().getTransportProtocol().equals(TransportProtocol.HTTP)) { TypeName rpcStubClassName = new TypeName( context .getNamer() .getFullyQualifiedRpcStubType( context.getInterfaceConfig().getInterfaceModel(), context.getProductConfig().getTransportProtocol())); return context .getTypeTable() .getAndSaveNicknameForInnerType( rpcStubClassName.getFullName(), context.getNamer().getMethodDescriptorName(context.getMethodModel())); } return null; }
@Override public String getAndSavePagedResponseTypeName( MethodContext methodContext, FieldConfig resourcesFieldConfig) { return methodContext .getMethodModel() .getAndSaveResponseTypeName(methodContext.getTypeTable(), methodContext.getNamer()); }
@Override public String getStaticLangReturnTypeName(MethodContext methodContext) { return methodContext .getMethodModel() .getOutputTypeName(methodContext.getTypeTable()) .getFullName(); }
private void setStaticLangGrpcStreamingReturnTypeName( MethodContext context, StaticLangApiMethodView.Builder methodViewBuilder) { SurfaceNamer namer = context.getNamer(); // use the api return type name as the surface return type name String returnTypeFullName = namer.getGrpcStreamingApiReturnTypeName(context, context.getTypeTable()); String returnTypeNickname = context.getTypeTable().getAndSaveNicknameFor(returnTypeFullName); methodViewBuilder.responseTypeName(returnTypeNickname); }
StaticLangApiMethodView.Builder methodViewBuilder, List<CallingForm> callingForms) { MethodModel method = context.getMethodModel(); SurfaceNamer namer = context.getNamer(); List<ParamDocView> paramDocs = new ArrayList<>(); paramDocs.addAll(getRequestObjectParamDocs(context)); methodViewBuilder.doc( ApiMethodDocView.newBuilder() .mainDocLines(namer.getDocLines(method, context.getMethodConfig())) .paramDocs(paramDocs) .throwsDocLines(namer.getThrowsDocLines(context.getMethodConfig())) .returnsDocLines( namer.getReturnDocLines(context.getSurfaceInterfaceContext(), context, sync)) .build()); methodViewBuilder, context, context.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, initCodeContext -> initCodeTransformer.generateInitCode( context.cloneWithEmptyTypeTable(), initCodeContext), callingForms); RequestObjectMethodDetailView.newBuilder(); detailBuilder.accessModifier( context.getNamer().getVisiblityKeyword(context.getMethodConfig().getVisibility())); detailBuilder.callableMethodName(callableMethodName);
private List<PathTemplateCheckView> generatePathTemplateChecks( MethodContext context, Iterable<FieldConfig> fieldConfigs) { List<PathTemplateCheckView> pathTemplateChecks = new ArrayList<>(); if (!context.getFeatureConfig().enableStringFormatFunctions()) { return pathTemplateChecks; context.getMethodConfig().getFieldNamePatterns(); String entityName = fieldNamePatterns.get(field.getSimpleName()); if (entityName != null) { SingleResourceNameConfig resourceNameConfig = context.getSingleResourceNameConfig(entityName); if (resourceNameConfig == null) { String methodName = context.getMethodModel().getSimpleName(); throw new IllegalStateException( "No collection config with id '" check.pathTemplateName( context .getNamer() .getPathTemplateName(context.getInterfaceConfig(), resourceNameConfig)); check.paramName(context.getNamer().getVariableName(field)); check.allowEmptyString(shouldAllowEmpty(context, field)); check.validationMessageContext( context .getNamer() .getApiMethodName( context.getMethodModel(), context.getMethodConfig().getVisibility())); pathTemplateChecks.add(check.build());
public StaticLangApiMethodView generatePagedFlattenedAsyncMethod( MethodContext context, List<ParamWithSimpleDoc> additionalParams) { MethodModel methodModel = context.getMethodModel(); SurfaceNamer namer = context.getNamer(); StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder(); setCommonFields(context, methodViewBuilder); methodViewBuilder.name( namer.getAsyncApiMethodName(methodModel, context.getMethodConfig().getVisibility())); methodViewBuilder.exampleName(namer.getAsyncApiMethodExampleName(methodModel)); setListMethodFields(context, Synchronicity.Async, methodViewBuilder); setFlattenedMethodFields( context, additionalParams, Synchronicity.Async, methodViewBuilder, Arrays.asList(CallingForm.FlattenedAsyncPaged)); return methodViewBuilder.type(ClientMethodType.PagedFlattenedAsyncMethod).build(); }
private StaticLangApiMethodSnippetView generatePagedRequestMethod(MethodContext methodContext) { StaticLangApiMethodView method = generateInitCode( apiMethodTransformer.generatePagedRequestObjectMethod( methodContext, csharpCommonTransformer.pagedMethodAdditionalParams()), methodContext, methodContext.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, CallingForm.RequestPaged); SurfaceNamer namer = methodContext.getNamer(); PageStreamingConfig pageStreaming = methodContext.getMethodConfig().getPageStreaming(); FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig(); String callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, resourceFieldConfig); return StaticLangApiMethodSnippetView.newBuilder() .method(method) .snippetMethodName(method.name() + "_RequestObject") .callerResponseTypeName(callerResponseTypeName) .apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())) .apiVariableName(method.apiVariableName()) .build(); }
public ApiCallSettingsView generateApiCallableSettings( MethodContext context, ApiCallableImplType callableImplType) { SurfaceNamer namer = context.getNamer(); ImportTypeTable typeTable = context.getTypeTable(); MethodModel method = context.getMethodModel(); MethodConfig methodConfig = context.getMethodConfig(); context.getSurfaceInterfaceContext())) { retryCodesByKey.put(retryCodes.key(), retryCodes); for (RetryParamsDefinitionView retryParams : retryDefinitionsTransformer.generateRetryParamsDefinitions( context.getSurfaceInterfaceContext())) { retryParamsByKey.put(retryParams.key(), retryParams); settings.asyncMethodName(namer.getAsyncApiMethodName(method, VisibilityConfig.PUBLIC)); settings.requestTypeName( method.getAndSaveRequestTypeName(context.getTypeTable(), context.getNamer())); settings.responseTypeName( method.getAndSaveResponseTypeName(context.getTypeTable(), context.getNamer())); typeTable.getAndSaveNicknameFor(context.getGrpcContainerTypeName()); settings.retryCodesName(methodConfig.getRetryCodesConfigName()); settings.retryCodesView(retryCodesByKey.get(methodConfig.getRetryCodesConfigName()));
InitCodeNode item, boolean isFirstItem) { SurfaceNamer namer = context.getNamer(); ImportTypeTable typeTable = context.getTypeTable(); InitValueConfig initValueConfig = item.getInitValueConfig(); FieldConfig fieldConfig = item.getFieldConfig(); if (context.getFeatureConfig().useResourceNameFormatOptionInSample(context, fieldConfig)) { if (!context.isFlattenedMethodContext()) { ResourceNameConfig messageResNameConfig = fieldConfig.getMessageResourceNameConfig(); if (messageResNameConfig == null RepeatedResourceNameInitValueView.newBuilder() .resourceTypeName( namer.getAndSaveElementResourceTypeName(context.getTypeTable(), fieldConfig)) .build(); } else { Iterables.get(context.getProductConfig().getSingleResourceNameConfigs(), 0); FieldConfig anyResourceNameFieldConfig = fieldConfig.withResourceNameConfig(singleResourceNameConfig); if (context.getFeatureConfig().enableStringFormatFunctions() || fieldConfig.getResourceNameConfig() == null) { FormattedInitValueView.Builder formattedInitValue = FormattedInitValueView.newBuilder(); context.getNamer().getApiWrapperClassName(context.getInterfaceConfig())); formattedInitValue.fullyQualifiedApiWrapperName( context.getNamer().getFullyQualifiedApiWrapperClassName(context.getInterfaceConfig()));
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(); }
private HttpMethodView generateHttpFields(MethodContext context) { if (context.getProductConfig().getTransportProtocol().equals(TransportProtocol.HTTP)) { Method method = ((DiscoveryMethodModel) context.getMethodModel()).getDiscoMethod(); HttpMethodView.Builder httpMethodView = HttpMethodView.newBuilder(); httpMethodView.fullMethodName(method.id()); (DiscoGapicInterfaceConfig) context.getSurfaceInterfaceContext().getInterfaceConfig(); SingleResourceNameConfig nameConfig = interfaceConfig.methodToResourceNameMap().get(context.getMethodConfig()); httpMethodView.resourceNameTypeName( context.getNamer().publicClassName(DiscoGapicParser.getResourceNameName(nameConfig))); for (FieldConfig fieldConfig : context.getMethodConfig().getRequiredFieldConfigs()) { if (fieldConfig.getResourceNameConfig() != null && fieldConfig.getResourceNameConfig().equals(nameConfig)) { httpMethodView.resourceNameFieldName( context .getNamer() .privateFieldName(Name.anyCamel(fieldConfig.getField().getNameAsParameter())));
private MockRpcResponseView createMockResponseView( MethodContext methodContext, InitCodeContext responseInitCodeContext) { methodContext = methodContext .getSurfaceInterfaceContext() .asRequestMethodContext(methodContext.getMethodModel()); InitCodeView initCodeView = initCodeTransformer.generateInitCode(methodContext, responseInitCodeContext); String typeName = methodContext .getMethodModel() .getAndSaveResponseTypeName(methodContext.getTypeTable(), methodContext.getNamer()); return MockRpcResponseView.newBuilder() .typeName(typeName) .rpcResponseInitCode(initCodeView) .build(); }
private StaticLangApiMethodSnippetView generateFlattenedMethod( MethodContext methodContext, String suffix) { StaticLangApiMethodView method = generateInitCode( apiMethodTransformer.generateFlattenedMethod(methodContext), methodContext, methodContext.getFlatteningConfig().getFlattenedFieldConfigs().values(), InitCodeOutputType.FieldList, CallingForm.Flattened); SurfaceNamer namer = methodContext.getNamer(); String callerResponseTypeName = methodContext .getTypeTable() .getAndSaveNicknameFor(namer.getStaticLangCallerReturnTypeName(methodContext)); return StaticLangApiMethodSnippetView.newBuilder() .method(method) .snippetMethodName(method.name() + suffix) .callerResponseTypeName(callerResponseTypeName) .apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())) .apiVariableName(method.apiVariableName()) .build(); }
private StaticLangApiMethodSnippetView generatePagedFlattenedMethod( MethodContext methodContext, String suffix, boolean requiresNamedArguments) { StaticLangApiMethodView method = generateInitCode( apiMethodTransformer.generatePagedFlattenedMethod( methodContext, csharpCommonTransformer.pagedMethodAdditionalParams()), methodContext, methodContext.getFlatteningConfig().getFlattenedFieldConfigs().values(), InitCodeOutputType.FieldList, CallingForm.FlattenedPaged); SurfaceNamer namer = methodContext.getNamer(); PageStreamingConfig pageStreaming = methodContext.getMethodConfig().getPageStreaming(); FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig(); String callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, resourceFieldConfig); return StaticLangApiMethodSnippetView.newBuilder() .method(method) .snippetMethodName(method.name() + suffix) .callerResponseTypeName(callerResponseTypeName) .apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())) .apiVariableName(method.apiVariableName()) .requiresNamedArguments(requiresNamedArguments) .build(); }
/** * A utility method which creates the InitValueConfig map that contains the collection config * data. */ public static ImmutableMap<String, InitValueConfig> createCollectionMap(MethodContext context) { ImmutableMap.Builder<String, InitValueConfig> mapBuilder = ImmutableMap.builder(); Map<String, String> fieldNamePatterns = context.getMethodConfig().getFieldNamePatterns(); for (Map.Entry<String, String> fieldNamePattern : fieldNamePatterns.entrySet()) { SingleResourceNameConfig resourceNameConfig = context.getSingleResourceNameConfig(fieldNamePattern.getValue()); String apiWrapperClassName = context.getNamer().getApiWrapperClassName(context.getInterfaceConfig()); InitValueConfig initValueConfig = InitValueConfig.create(apiWrapperClassName, resourceNameConfig); mapBuilder.put(fieldNamePattern.getKey(), initValueConfig); } return mapBuilder.build(); }
@Override public List<String> getReturnDocLines( TransformationContext context, MethodContext methodContext, Synchronicity synchronicity) { MethodModel method = methodContext.getMethodModel(); MethodConfig methodConfig = methodContext.getMethodConfig(); if (method.getResponseStreaming()) { String classInfo = method.getOutputTypeName(methodContext.getTypeTable()).getFullName(); return ImmutableList.of("An enumerable of " + classInfo + " instances.", ""); } if (methodConfig.isPageStreaming()) { String resourceTypeName = getTypeFormatter() .getFullNameForElementType(methodConfig.getPageStreaming().getResourcesField()); return ImmutableList.of( "An enumerable of " + resourceTypeName + " instances.", "See Google::Gax::PagedEnumerable documentation for other", "operations such as per-page iteration or access to the response", "object."); } return ImmutableList.of(); }
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(); }