use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class JavaSurfaceTransformer method generateRpcStubClass.
private StaticLangRpcStubView generateRpcStubClass(InterfaceContext context, GapicProductConfig productConfig) {
SurfaceNamer namer = context.getNamer();
InterfaceConfig interfaceConfig = context.getInterfaceConfig();
addRpcStubImports(context);
// Stub class has different default package name from method, request, and resource classes.
InterfaceContext apiMethodsContext = context.withNewTypeTable(context.getNamer().getRootPackageName());
List<StaticLangApiMethodView> methods = generateApiMethods(apiMethodsContext);
StaticLangRpcStubView.Builder stubClass = StaticLangRpcStubView.newBuilder();
stubClass.doc(serviceTransformer.generateServiceDoc(context, null, productConfig));
String name = namer.getApiRpcStubClassName(interfaceConfig.getInterfaceModel(), productConfig.getTransportProtocol());
stubClass.releaseLevelAnnotation(namer.getReleaseAnnotation(ReleaseLevel.BETA));
stubClass.name(name);
stubClass.parentName(namer.getApiStubInterfaceName(interfaceConfig));
stubClass.settingsClassName(getAndSaveNicknameForRootType(apiMethodsContext, namer.getApiSettingsClassName(interfaceConfig)));
stubClass.stubSettingsClassName(getAndSaveNicknameForStubType(apiMethodsContext, namer.getApiStubSettingsClassName(interfaceConfig)));
stubClass.callableFactoryClassName(getAndSaveNicknameForStubType(apiMethodsContext, namer.getCallableFactoryClassName(interfaceConfig, productConfig.getTransportProtocol())));
stubClass.methodDescriptors(apiCallableTransformer.generateMethodDescriptors(apiMethodsContext));
stubClass.apiCallables(apiCallableTransformer.generateStaticLangApiCallables(apiMethodsContext));
stubClass.callableMethods(filterIncludeCallableMethods(methods));
stubClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
stubClass.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations());
for (TypeAlias alias : apiMethodsContext.getImportTypeTable().getTypeTable().getAllImports().values()) {
context.getImportTypeTable().getAndSaveNicknameFor(alias);
}
return stubClass.build();
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class JavaSurfaceTransformer method getAndSaveNicknameForRootType.
private String getAndSaveNicknameForRootType(InterfaceContext context, String nickname) {
SurfaceNamer namer = context.getNamer();
ImportTypeTable typeTable = context.getImportTypeTable();
String fullyQualifiedTypeName = namer.getRootPackageName() + "." + nickname;
return typeTable.getAndSaveNicknameFor(fullyQualifiedTypeName);
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class JavaSurfaceTransformer method generateSettingsDoc.
private SettingsDocView generateSettingsDoc(InterfaceContext context, StaticLangApiMethodView exampleApiMethod, GapicProductConfig productConfig, String settingsClassName, String apiClassName) {
SurfaceNamer namer = context.getNamer();
SettingsDocView.Builder settingsDoc = SettingsDocView.newBuilder();
ApiModel model = context.getApiModel();
settingsDoc.serviceAddress(model.getServiceAddress());
settingsDoc.servicePort(model.getServicePort());
settingsDoc.transportProtocol(productConfig.getTransportProtocol());
settingsDoc.exampleApiMethodName(exampleApiMethod.name());
settingsDoc.exampleApiMethodSettingsGetter(exampleApiMethod.settingsGetterName());
settingsDoc.apiClassName(apiClassName);
settingsDoc.settingsVarName(namer.getApiSettingsVariableName(context.getInterfaceConfig()));
settingsDoc.settingsClassName(settingsClassName);
settingsDoc.settingsBuilderVarName(namer.getApiSettingsBuilderVarName(context.getInterfaceConfig()));
settingsDoc.hasDefaultInstance(context.getInterfaceConfig().hasDefaultInstance());
return settingsDoc.build();
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class JavaSurfaceTransformer method generateStubSettingsClass.
private StaticLangStubSettingsView generateStubSettingsClass(InterfaceContext context, GapicProductConfig productConfig, StaticLangApiMethodView exampleApiMethod) {
addSettingsImports(context);
SurfaceNamer namer = context.getNamer();
InterfaceConfig interfaceConfig = context.getInterfaceConfig();
ApiModel model = context.getApiModel();
StaticLangStubSettingsView.Builder xsettingsClass = StaticLangStubSettingsView.newBuilder();
xsettingsClass.releaseLevelAnnotation(context.getNamer().getReleaseAnnotation(packageMetadataConfig.releaseLevel(TargetLanguage.JAVA)));
xsettingsClass.doc(generateSettingsDoc(context, exampleApiMethod, productConfig, context.getNamer().getApiStubSettingsClassName(interfaceConfig), namer.getApiStubInterfaceName(context.getInterfaceConfig())));
String name = namer.getApiStubSettingsClassName(context.getInterfaceConfig());
xsettingsClass.name(name);
xsettingsClass.serviceAddress(model.getServiceAddress());
xsettingsClass.servicePort(model.getServicePort());
xsettingsClass.authScopes(model.getAuthScopes());
if (productConfig.getTransportProtocol().equals(TransportProtocol.HTTP)) {
xsettingsClass.useDefaultServicePortInEndpoint(false);
}
xsettingsClass.transportProtocol(productConfig.getTransportProtocol());
xsettingsClass.rpcTransportName(namer.getTransportClassName(productConfig.getTransportProtocol()));
xsettingsClass.transportNameGetter(namer.getTransporNameGetMethod(productConfig.getTransportProtocol()));
xsettingsClass.defaultTransportProviderBuilder(namer.getDefaultTransportProviderBuilder(productConfig.getTransportProtocol()));
xsettingsClass.transportProvider(namer.getTransportProvider(productConfig.getTransportProtocol()));
xsettingsClass.instantiatingChannelProvider(namer.getInstantiatingChannelProvider(productConfig.getTransportProtocol()));
List<ApiCallSettingsView> apiCallSettings = apiCallableTransformer.generateCallSettings(context);
xsettingsClass.callSettings(apiCallSettings);
xsettingsClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptorClasses(context));
xsettingsClass.pagedListResponseFactories(pageStreamingTransformer.generateFactoryClasses(context));
xsettingsClass.batchingDescriptors(batchingTransformer.generateDescriptorClasses(context));
xsettingsClass.retryCodesDefinitions(retryDefinitionsTransformer.generateRetryCodesDefinitions(context));
xsettingsClass.retryParamsDefinitions(retryDefinitionsTransformer.generateRetryParamsDefinitions(context));
xsettingsClass.transportProtocol(productConfig.getTransportProtocol());
xsettingsClass.hasDefaultServiceAddress(interfaceConfig.hasDefaultServiceAddress());
xsettingsClass.hasDefaultServiceScopes(interfaceConfig.hasDefaultServiceScopes());
xsettingsClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance());
xsettingsClass.stubInterfaceName(getAndSaveNicknameForStubType(context, namer.getApiStubInterfaceName(interfaceConfig)));
xsettingsClass.rpcStubClassName(getAndSaveNicknameForStubType(context, namer.getApiRpcStubClassName(interfaceConfig.getInterfaceModel(), productConfig.getTransportProtocol())));
return xsettingsClass.build();
}
use of com.google.api.codegen.transformer.SurfaceNamer in project toolkit by googleapis.
the class NodeJSGapicSurfaceDocTransformer method generateDoc.
private ViewModel generateDoc(ProtoFile file, GapicProductConfig productConfig) {
ModelTypeTable typeTable = new ModelTypeTable(new JSTypeTable(productConfig.getPackageName()), new NodeJSModelTypeNameConverter(productConfig.getPackageName()));
// Use file path for package name to get file-specific package instead of package for the API.
SurfaceNamer namer = new NodeJSSurfaceNamer(productConfig.getPackageName(), NodeJSUtils.isGcloud(productConfig));
JSCommentReformatter commentReformatter = new JSCommentReformatter();
GrpcDocView.Builder doc = GrpcDocView.newBuilder();
doc.templateFileName(DOC_TEMPLATE_FILENAME);
doc.outputPath(getOutputPath(namer, file));
doc.fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, ImportSectionView.newBuilder().build(), namer));
doc.elementDocs(grpcElementDocTransformer.generateElementDocs(typeTable, namer, file));
return doc.build();
}
Aggregations