private List<ImportFileView> generateExternalImports(InterfaceContext context) { ImmutableList.Builder<ImportFileView> imports = ImmutableList.builder(); InterfaceModel apiInterface = context.getInterfaceModel(); InterfaceConfig interfaceConfig = context.getInterfaceConfig(); String configModule = context.getNamer().getClientConfigPath(interfaceConfig); imports.add(createImport("gapicConfig", "./" + configModule)); imports.add(createImport("gax", "google-gax")); imports.add(createImport("merge", "lodash.merge")); imports.add(createImport("path", "path")); if (context.getInterfaceConfig().hasLongRunningOperations() || context.getInterfaceConfig().hasBatchingMethods()) { imports.add(createImport("protobuf", "protobufjs")); } return imports.build(); }
private List<ImportFileView> generateFileHeaderExternalImports(InterfaceContext context) { List<ImportFileView> imports = new ArrayList<>(); imports.add(createImport("grpc")); imports.add(createImport("google.oauth2", "service_account")); imports.add(createImport("google.api_core.grpc_helpers")); imports.add(createImport("google.api_core.gapic_v1.client_info")); imports.add(createImport("google.api_core.gapic_v1.config")); imports.add(createImport("google.api_core.gapic_v1.method")); if (hasRequestHeaderParams((GapicInterfaceContext) context)) { imports.add(createImport("google.api_core.gapic_v1.routing_header")); } if (context.getInterfaceConfig().hasLongRunningOperations()) { imports.add(createImport("google.api_core.operations_v1")); imports.add(createImport("google.api_core.operation")); } if (context.getInterfaceConfig().hasPageStreamingMethods()) { imports.add(createImport("google.api_core.page_iterator")); } if (!(new PathTemplateTransformer().generateFormatResourceFunctions(context)).isEmpty()) { imports.add(createImport("google.api_core.path_template")); } if (hasOneOf(context)) { imports.add(createImport("google.api_core.protobuf_helpers")); } Collections.sort(imports, importFileViewComparator()); return imports; }
private void addStubInterfaceImports(InterfaceContext context) { ImportTypeTable typeTable = context.getImportTypeTable(); typeTable.saveNicknameFor("com.google.api.core.BetaApi"); typeTable.saveNicknameFor("com.google.api.gax.core.BackgroundResource"); typeTable.saveNicknameFor("com.google.api.gax.rpc.UnaryCallable"); typeTable.saveNicknameFor("javax.annotation.Generated"); typeTable.saveNicknameFor("java.lang.Void"); InterfaceConfig interfaceConfig = context.getInterfaceConfig(); if (interfaceConfig.hasLongRunningOperations()) { typeTable.saveNicknameFor("com.google.longrunning.Operation"); typeTable.saveNicknameFor("com.google.longrunning.stub.OperationsStub"); } }
private StaticLangStubInterfaceView generateStubInterface( InterfaceContext context, GapicProductConfig productConfig) { InterfaceConfig interfaceConfig = context.getInterfaceConfig(); addStubInterfaceImports(context); // Stub class has different default package name from methods classes. InterfaceContext apiMethodsContext = context.withNewTypeTable(context.getNamer().getRootPackageName()); List<StaticLangApiMethodView> methods = methodGenerator.generateApiMethods(apiMethodsContext); for (TypeAlias alias : apiMethodsContext.getImportTypeTable().getTypeTable().getAllImports().values()) { context.getImportTypeTable().getAndSaveNicknameFor(alias); } StaticLangStubInterfaceView.Builder stubInterface = StaticLangStubInterfaceView.newBuilder(); stubInterface.doc(serviceTransformer.generateServiceDoc(context, null, productConfig)); String name = context.getNamer().getApiStubInterfaceName(context.getInterfaceConfig()); stubInterface.releaseLevelAnnotation( context.getNamer().getReleaseAnnotation(productConfig.getReleaseLevel())); stubInterface.name(name); stubInterface.callableMethods(filterIncludeCallableMethods(methods)); stubInterface.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations()); return stubInterface.build(); }
private void addApiImports(InterfaceContext context) { ImportTypeTable typeTable = context.getImportTypeTable(); typeTable.saveNicknameFor("com.google.api.core.BetaApi"); typeTable.saveNicknameFor("com.google.api.gax.core.BackgroundResource"); typeTable.saveNicknameFor("com.google.api.gax.rpc.UnaryCallable"); typeTable.saveNicknameFor("com.google.api.pathtemplate.PathTemplate"); typeTable.saveNicknameFor("java.io.Closeable"); typeTable.saveNicknameFor("java.io.IOException"); typeTable.saveNicknameFor("java.util.concurrent.TimeUnit"); typeTable.saveNicknameFor("javax.annotation.Generated"); if (context.getInterfaceConfig().hasLongRunningOperations()) { typeTable.saveNicknameFor("com.google.api.gax.longrunning.OperationFuture"); typeTable.saveNicknameFor("com.google.longrunning.Operation"); typeTable.saveNicknameFor("com.google.longrunning.OperationsClient"); } switch (context.getProductConfig().getTransportProtocol()) { case HTTP: typeTable.saveNicknameFor("java.util.List"); typeTable.saveNicknameFor("java.util.ArrayList"); typeTable.saveNicknameFor("java.util.concurrent.ScheduledExecutorService"); } }
typeTable.saveNicknameFor("com.google.api.gax.rpc.ClientStreamingCallable"); if (interfaceConfig.hasLongRunningOperations()) { typeTable.saveNicknameFor("com.google.api.gax.longrunning.OperationSnapshot"); typeTable.saveNicknameFor("io.grpc.MethodDescriptor"); typeTable.saveNicknameFor("io.grpc.protobuf.ProtoUtils"); if (interfaceConfig.hasLongRunningOperations()) { typeTable.saveNicknameFor("com.google.longrunning.Operation"); typeTable.saveNicknameFor("com.google.longrunning.stub.GrpcOperationsStub");
stubClass.callableMethods(filterIncludeCallableMethods(methods)); stubClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance()); stubClass.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations());
private StaticLangApiView generateApiClass( InterfaceContext context, GapicProductConfig productConfig) { SurfaceNamer namer = context.getNamer(); InterfaceConfig interfaceConfig = context.getInterfaceConfig(); addApiImports(context); List<StaticLangApiMethodView> methods = methodGenerator.generateApiMethods(context); StaticLangApiView.Builder xapiClass = StaticLangApiView.newBuilder(); ApiMethodView exampleApiMethod = getExampleApiMethod(methods); xapiClass.doc(serviceTransformer.generateServiceDoc(context, exampleApiMethod, productConfig)); String name = context.getNamer().getApiWrapperClassName(context.getInterfaceConfig()); xapiClass.releaseLevelAnnotation(namer.getReleaseAnnotation(productConfig.getReleaseLevel())); xapiClass.name(name); xapiClass.settingsClassName(namer.getApiSettingsClassName(interfaceConfig)); xapiClass.stubInterfaceName( getAndSaveNicknameForStubType(context, namer.getApiStubInterfaceName(interfaceConfig))); xapiClass.stubSettingsClassName( getAndSaveNicknameForStubType(context, namer.getApiStubSettingsClassName(interfaceConfig))); xapiClass.apiCallableMembers(apiCallableTransformer.generateStaticLangApiCallables(context)); xapiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context)); xapiClass.formatResourceFunctions( pathTemplateTransformer.generateFormatResourceFunctions(context)); xapiClass.parseResourceFunctions( pathTemplateTransformer.generateParseResourceFunctions(context)); xapiClass.apiMethods(methods); xapiClass.hasDefaultInstance(interfaceConfig.hasDefaultInstance()); xapiClass.hasLongRunningOperations(interfaceConfig.hasLongRunningOperations()); xapiClass.pagedResponseViews(generatePagedResponseWrappers(context)); return xapiClass.build(); }
typeTable.saveNicknameFor("com.google.api.gax.rpc.StreamingCallSettings"); if (interfaceConfig.hasLongRunningOperations()) { typeTable.saveNicknameFor("com.google.api.gax.longrunning.OperationSnapshot"); typeTable.saveNicknameFor("com.google.api.gax.rpc.OperationCallSettings"); typeTable.saveNicknameFor("com.google.api.gax.grpc.GrpcTransportChannel"); typeTable.saveNicknameFor("com.google.api.gax.grpc.InstantiatingGrpcChannelProvider"); if (interfaceConfig.hasLongRunningOperations()) { typeTable.saveNicknameFor("com.google.api.gax.grpc.ProtoOperationTransformers");
typeTable.saveNicknameFor("org.junit.BeforeClass"); typeTable.saveNicknameFor("org.junit.Test"); if (context.getInterfaceConfig().hasLongRunningOperations()) { typeTable.saveNicknameFor("com.google.protobuf.Any");