1717import com .google .api .core .BetaApi ;
1818import com .google .api .gax .core .BackgroundResource ;
1919import com .google .api .gax .core .BackgroundResourceAggregation ;
20+ import com .google .api .gax .longrunning .OperationSnapshot ;
2021import com .google .api .gax .rpc .BidiStreamingCallable ;
2122import com .google .api .gax .rpc .ClientContext ;
2223import com .google .api .gax .rpc .ClientStreamingCallable ;
@@ -119,6 +120,7 @@ private static TypeStore createStaticTypes() {
119120 IOException .class ,
120121 Operation .class ,
121122 OperationCallable .class ,
123+ OperationSnapshot .class ,
122124 RequestParamsExtractor .class ,
123125 ServerStreamingCallable .class ,
124126 TimeUnit .class ,
@@ -161,7 +163,7 @@ public GapicClass generate(GapicContext context, Service service) {
161163 }
162164
163165 boolean operationPollingMethod = checkOperationPollingMethod (service );
164- if (operationPollingMethod ) {
166+ if (operationPollingMethod ) {
165167 VariableExpr longRunningVarExpr = declareLongRunningClient ();
166168 if (longRunningVarExpr != null ) {
167169 classMemberVarExprs .put ("longRunningClient" , longRunningVarExpr );
@@ -212,7 +214,10 @@ public GapicClass generate(GapicContext context, Service service) {
212214 }
213215
214216 protected abstract Statement createMethodDescriptorVariableDecl (
215- Service service , Method protoMethod , VariableExpr methodDescriptorVarExpr , Map <String , Message > messageTypes );
217+ Service service ,
218+ Method protoMethod ,
219+ VariableExpr methodDescriptorVarExpr ,
220+ Map <String , Message > messageTypes );
216221
217222 protected boolean generateOperationsStubLogic (Service service ) {
218223 return true ;
@@ -227,7 +232,8 @@ protected List<MethodDefinition> createOperationsStubGetterMethod(
227232 String methodName =
228233 String .format (
229234 "get%s" ,
230- JavaStyle .toUpperCamelCase (getTransportContext ().transportOperationsStubNames ().get (0 )));
235+ JavaStyle .toUpperCamelCase (
236+ getTransportContext ().transportOperationsStubNames ().get (0 )));
231237
232238 return Arrays .asList (
233239 MethodDefinition .builder ()
@@ -248,15 +254,26 @@ protected List<MethodDefinition> createGetMethodDescriptorsMethod(
248254 return Arrays .asList ();
249255 }
250256
257+ protected List <Statement > createTypeRegistry (Service service ) {
258+ return Arrays .asList ();
259+ }
260+
251261 protected List <Statement > createClassStatements (
252262 Service service ,
253263 Map <String , VariableExpr > protoMethodNameToDescriptorVarExprs ,
254264 Map <String , VariableExpr > callableClassMemberVarExprs ,
255265 Map <String , VariableExpr > classMemberVarExprs ,
256266 Map <String , Message > messageTypes ) {
257267 List <Statement > classStatements = new ArrayList <>();
268+
269+ classStatements .addAll (createTypeRegistry (service ));
270+ if (!classStatements .isEmpty ()) {
271+ classStatements .add (EMPTY_LINE_STATEMENT );
272+ }
273+
258274 for (Statement statement :
259- createMethodDescriptorVariableDecls (service , protoMethodNameToDescriptorVarExprs , messageTypes )) {
275+ createMethodDescriptorVariableDecls (
276+ service , protoMethodNameToDescriptorVarExprs , messageTypes )) {
260277 classStatements .add (statement );
261278 classStatements .add (EMPTY_LINE_STATEMENT );
262279 }
@@ -265,11 +282,15 @@ protected List<Statement> createClassStatements(
265282 classStatements .add (EMPTY_LINE_STATEMENT );
266283
267284 classStatements .addAll (createClassMemberFieldDeclarations (classMemberVarExprs ));
285+ classStatements .add (EMPTY_LINE_STATEMENT );
286+
268287 return classStatements ;
269288 }
270289
271290 protected List <Statement > createMethodDescriptorVariableDecls (
272- Service service , Map <String , VariableExpr > protoMethodNameToDescriptorVarExprs , Map <String , Message > messageTypes ) {
291+ Service service ,
292+ Map <String , VariableExpr > protoMethodNameToDescriptorVarExprs ,
293+ Map <String , Message > messageTypes ) {
273294 return service .methods ().stream ()
274295 .map (
275296 m ->
@@ -418,14 +439,17 @@ protected List<MethodDefinition> createClassMethods(
418439 createGetMethodDescriptorsMethod (service , typeStore , protoMethodNameToDescriptorVarExprs ));
419440 javaMethods .addAll (
420441 createOperationsStubGetterMethod (
421- service , classMemberVarExprs .get (getTransportContext ().transportOperationsStubNames ().get (0 ))));
442+ service ,
443+ classMemberVarExprs .get (getTransportContext ().transportOperationsStubNames ().get (0 ))));
422444 javaMethods .addAll (createCallableGetterMethods (callableClassMemberVarExprs ));
423445 javaMethods .addAll (
424- createStubOverrideMethods (classMemberVarExprs .get (BACKGROUND_RESOURCES_MEMBER_NAME ), service ));
446+ createStubOverrideMethods (
447+ classMemberVarExprs .get (BACKGROUND_RESOURCES_MEMBER_NAME ), service ));
425448 return javaMethods ;
426449 }
427450
428- protected List <MethodDefinition > createStaticCreatorMethods (Service service , TypeStore typeStore , String newBuilderMethod ) {
451+ protected List <MethodDefinition > createStaticCreatorMethods (
452+ Service service , TypeStore typeStore , String newBuilderMethod ) {
429453 TypeNode creatorMethodReturnType =
430454 typeStore .get (getTransportContext ().classNames ().getTransportServiceStubClassName (service ));
431455 Function <List <VariableExpr >, MethodDefinition .Builder > creatorMethodStarterFn =
@@ -584,22 +608,16 @@ protected List<MethodDefinition> createConstructorMethods(
584608 .build ())
585609 .setValueExpr (callableFactoryVarExpr )
586610 .build ());
587- VariableExpr operationsStubClassVarExpr = classMemberVarExprs .get (getTransportContext ().transportOperationsStubNames ().get (0 ));
588- //TODO: refactor this
611+ VariableExpr operationsStubClassVarExpr =
612+ classMemberVarExprs .get (getTransportContext ().transportOperationsStubNames ().get (0 ));
613+ // TODO: refactor this
589614 if (generateOperationsStubLogic (service )) {
590- TypeNode opeationsStubType = getTransportOperationsStubType (service );
591- secondCtorExprs .add (
592- AssignmentExpr .builder ()
593- .setVariableExpr (
594- operationsStubClassVarExpr .toBuilder ().setExprReferenceExpr (thisExpr ).build ())
595- .setValueExpr (
596- MethodInvocationExpr .builder ()
597- .setStaticReferenceType (opeationsStubType )
598- .setMethodName ("create" )
599- .setArguments (Arrays .asList (clientContextVarExpr , callableFactoryVarExpr ))
600- .setReturnType (operationsStubClassVarExpr .type ())
601- .build ())
602- .build ());
615+ secondCtorExprs .addAll (createOperationsStubInitExpr (
616+ service ,
617+ thisExpr ,
618+ operationsStubClassVarExpr ,
619+ clientContextVarExpr ,
620+ callableFactoryVarExpr ));
603621 }
604622 secondCtorStatements .addAll (
605623 secondCtorExprs .stream ().map (e -> ExprStatement .withExpr (e )).collect (Collectors .toList ()));
@@ -665,7 +683,6 @@ protected List<MethodDefinition> createConstructorMethods(
665683 secondCtorExprs .clear ();
666684 secondCtorStatements .add (EMPTY_LINE_STATEMENT );
667685
668-
669686 secondCtorStatements .addAll (createLongRunningClient (service , typeStore ));
670687
671688 // Instantiate backgroundResources.
@@ -699,6 +716,27 @@ protected List<MethodDefinition> createConstructorMethods(
699716 return Arrays .asList (firstCtor , secondCtor );
700717 }
701718
719+ protected List <Expr > createOperationsStubInitExpr (
720+ Service service ,
721+ Expr thisExpr ,
722+ VariableExpr operationsStubClassVarExpr ,
723+ VariableExpr clientContextVarExpr ,
724+ VariableExpr callableFactoryVarExpr ) {
725+ TypeNode opeationsStubType = getTransportOperationsStubType (service );
726+ return Collections .singletonList (
727+ AssignmentExpr .builder ()
728+ .setVariableExpr (
729+ operationsStubClassVarExpr .toBuilder ().setExprReferenceExpr (thisExpr ).build ())
730+ .setValueExpr (
731+ MethodInvocationExpr .builder ()
732+ .setStaticReferenceType (opeationsStubType )
733+ .setMethodName ("create" )
734+ .setArguments (Arrays .asList (clientContextVarExpr , callableFactoryVarExpr ))
735+ .setReturnType (operationsStubClassVarExpr .type ())
736+ .build ())
737+ .build ());
738+ }
739+
702740 protected List <Statement > createLongRunningClient (Service service , TypeStore typeStore ) {
703741 return ImmutableList .of ();
704742 }
@@ -963,8 +1001,8 @@ private List<MethodDefinition> createStubOverrideMethods(
9631001 }
9641002
9651003 private boolean checkOperationPollingMethod (Service service ) {
966- for (Method method : service .methods ()) {
967- if (method .isOperationPollingMethod ()) {
1004+ for (Method method : service .methods ()) {
1005+ if (method .isOperationPollingMethod ()) {
9681006 return true ;
9691007 }
9701008 }
@@ -1063,15 +1101,15 @@ protected TypeNode getTransportOperationsStubType(Service service) {
10631101 TypeNode transportOpeationsStubType = service .operationServiceStubType ();
10641102 if (transportOpeationsStubType == null ) {
10651103 transportOpeationsStubType = getTransportContext ().transportOperationsStubTypes ().get (0 );
1066- }
1067- else {
1068- transportOpeationsStubType = TypeNode .withReference (
1069- VaporReference .builder ()
1070- .setName ("HttpJson" + transportOpeationsStubType .reference ().simpleName ())
1071- .setPakkage (transportOpeationsStubType .reference ().pakkage ())
1072- .build ());
1104+ } else {
1105+ transportOpeationsStubType =
1106+ TypeNode .withReference (
1107+ VaporReference .builder ()
1108+ .setName ("HttpJson" + transportOpeationsStubType .reference ().simpleName ())
1109+ .setPakkage (transportOpeationsStubType .reference ().pakkage ())
1110+ .build ());
10731111 }
10741112
10751113 return transportOpeationsStubType ;
10761114 }
1077- }
1115+ }
0 commit comments